diff --git a/packages/projects-docs/pages/sdk/clients.mdx b/packages/projects-docs/pages/sdk/clients.mdx index 171548ef..9ebbb0a5 100644 --- a/packages/projects-docs/pages/sdk/clients.mdx +++ b/packages/projects-docs/pages/sdk/clients.mdx @@ -13,6 +13,10 @@ There are three different ways to connect to a Sandbox: - **Node**: When you want to connect to a Sandbox from a Node client environment, for example React Native - **Browser**: When you want to connect to a Sandbox from a browser client environment + +The browser and node clients use the same unified implementation, providing consistent behavior across both environments. + + ## SDK On your server, where you use the SDK, you can connect directly to a Sandbox: diff --git a/packages/projects-docs/pages/sdk/create-resume.mdx b/packages/projects-docs/pages/sdk/create-resume.mdx index 2416c335..3c24d087 100644 --- a/packages/projects-docs/pages/sdk/create-resume.mdx +++ b/packages/projects-docs/pages/sdk/create-resume.mdx @@ -23,7 +23,7 @@ const sandbox = await sdk.sandboxes.create(); ``` -By default Sandboxes are `unlisted` and can be accessed and forked by anyone with a url. If you want to create a private sandbox you can pass `privacy: 'private'`, which requires host tokens to access the exposed ports. +By default Sandboxes are `public` and can be accessed and forked by anyone with a url on CodeSandbox. Available privacy options are `private`, `public-hosts`, or `public`. Private sandboxes require host tokens to access exposed ports. If no `id` option is provided to `sandbox.create()`, we'll create a sandbox forked from our [Universal](https://codesandbox.io/p/devbox/universal-pcz35m) template on CodeSandbox. You can also pass in a specific template id from [our collection of templates](/sdk/snapshot-library) or by creating your own template using our [Template Builder](/sdk/templates). @@ -37,7 +37,7 @@ const sandbox = await sdk.sandboxes.create({ description: 'My sandbox', tags: ['my-tag'], - // Public, unlisted or private + // Privacy options: 'private', 'public-hosts', or 'public' privacy: 'private', // Collection folder on Dashboard @@ -67,6 +67,27 @@ const sandbox = await sdk.sandboxes.create({ The `automaticWakeupConfig` only wakes up the Sandbox, it does not extend its hibernation timeout. +## Get an Existing Sandbox + +To get information about an existing sandbox without resuming it, use `sdk.sandboxes.get(id)`: + +```ts +const sandbox = await sdk.sandboxes.get('sandbox-id'); +``` + +This method retrieves sandbox metadata and status without waking up a hibernated sandbox. + +## List Running Sandboxes + +To get a list of all currently running sandboxes, use `sdk.sandboxes.listRunning()`: + +```ts +const runningSandboxes = await sdk.sandboxes.listRunning(); +console.log(runningSandboxes); // Array of sandbox objects +``` + +This method returns an array of sandbox objects that are currently active and running. + ## Resume an Existing Sandbox To resume an existing sandbox from hibernation and connect to it call: `sdk.sandboxes.resume(id)`: diff --git a/packages/projects-docs/pages/sdk/hosts.mdx b/packages/projects-docs/pages/sdk/hosts.mdx index 9bef3ec2..176f0b1d 100644 --- a/packages/projects-docs/pages/sdk/hosts.mdx +++ b/packages/projects-docs/pages/sdk/hosts.mdx @@ -22,5 +22,5 @@ console.log(url) ``` -By default all Sandboxes are unlisted, but you need to use host tokens to access private Sandboxes. With public or unlisted Sandboxes the host tokens are not necessary, but you can still `getUrl` to generate a url for the relevant port. +By default all Sandboxes are public, but you need to use host tokens to access private Sandboxes. With public or public-hosts Sandboxes the host tokens are not necessary, but you can still `getUrl` to generate a url for the relevant port. diff --git a/packages/projects-docs/pages/sdk/index.mdx b/packages/projects-docs/pages/sdk/index.mdx index 09034f0f..337ed049 100644 --- a/packages/projects-docs/pages/sdk/index.mdx +++ b/packages/projects-docs/pages/sdk/index.mdx @@ -40,6 +40,22 @@ const output = await client.commands.run("echo 'Hello World'"); console.log(output) // Hello World ``` +### OpenTelemetry Support + +You can pass an OpenTelemetry tracer to the CodeSandbox constructor to enable tracing for all SDK operations: + +```js +import { CodeSandbox } from "@codesandbox/sdk"; +import { trace } from "@opentelemetry/api"; + +const tracer = trace.getTracer('my-app'); +const sdk = new CodeSandbox(process.env.CSB_API_KEY, { + tracer +}); +``` + +This will automatically trace all Sandboxes, Sandbox, and SandboxClient methods, including modules. + ## How it works The SDK can spin up a sandbox by cloning a template in under 3 seconds. Inside this VM you have a full development environment. diff --git a/packages/projects-docs/pages/sdk/templates.mdx b/packages/projects-docs/pages/sdk/templates.mdx index 4e30adfb..40b51d48 100644 --- a/packages/projects-docs/pages/sdk/templates.mdx +++ b/packages/projects-docs/pages/sdk/templates.mdx @@ -58,7 +58,7 @@ $ CSB_API_KEY=your-api-key npx @codesandbox/sdk build ./my-template --privacy pr ``` -The template defaults to a `Micro` VM Tier for both building the template and when creating Sandboxes from it. You can not "downsize" Sandboxes when creating them from a template, so make sure you set the minimum tier you want here. It is recommended to make templates private, but they default to "unlisted". Use `build --help` for documentation on all parameters. +The template defaults to a `Micro` VM Tier for both building the template and when creating Sandboxes from it. You can not "downsize" Sandboxes when creating them from a template, so make sure you set the minimum tier you want here. It is recommended to make templates private, but they default to "public". Use `build --help` for documentation on all parameters. This will start the process of creating Sandboxes for each of our clusters, write files, restart, wait for port 5173 to be available and then hibernate. This generates the snapshot that allows you to quickly create Sandboxes already running a dev server from the template.