This page covers the deprecated code sandbox SDK. Use the
together-sandbox SDK for new integrations.- Memory snapshot and restore (checkpointing) at any point in time.
- Resuming or cloning VMs from a snapshot in three seconds.
- VM filesystem persistence, with git version control.
- Environment customization using Docker and Docker Compose (Dev Containers).
Access
The legacy code sandbox is available on Together’s custom plans. A self-serve option is available by creating an account with CodeSandbox.CodeSandbox is a Together company, and its products are migrating to the Together platform. The
together-sandbox SDK is the successor to this offering. Within CodeSandbox.io, this offering is called the CodeSandbox SDK.Get started
Install the SDK:TypeScript
Sandbox lifecycle
By default a sandbox is created from a template. A template is a memory and filesystem snapshot of a sandbox, so a new sandbox is a direct continuation of the template. If the template was running a dev server, that dev server is running when the sandbox is created. When you create, resume, or restart a sandbox, you can read itsbootupType to see how it started:
FORK: The sandbox was created from a template. This happens when you callcreatesuccessfully.RUNNING: The sandbox was already running when you calledresume.RESUME: The sandbox was resumed from hibernation.CLEAN: The sandbox was created or resumed from scratch because it was not running and had no snapshot. This can happen if the sandbox was shut down or restarted, the snapshot expired, or something went wrong.
Manage CLEAN bootups
When a sandbox boots from scratch, the platform:
- Starts the Firecracker VM.
- Creates a default user, called pitcher-host.
- Builds the Docker image specified in
.devcontainer/devcontainer.json, if one is configured. - Starts the Docker container.
- Mounts the
/project/sandboxdirectory as a volume inside the Docker container.
JavaScript
Use templates
Code sandbox has default templates that you can use to create sandboxes. These templates are available in the Template Library, and the “Universal” template is used by default. To create your own template, use the CodeSandbox CLI.Create a template
Create a new folder in your project and add the files you want available inside your sandbox. For example, set up a Vite project:my-template/.codesandbox/tasks.json file with the following content:
setupTasks run after the sandbox has started, before any other tasks.
Deploy the template to the clusters:
The template is built with the Micro VM tier unless you pass
--vmTier to the build command.JavaScript
Connect to sandboxes in the browser
In addition to running your sandbox on the server, you can connect it to the browser. This requires some collaboration with the server:JavaScript
JavaScript
onFocusChange, and by default it reconnects when the page is visible:
JavaScript
connectToSandbox promise is resolving, you can listen to initialization events to show a loading state:
JavaScript
Disconnect the sandbox
Disconnecting the session ends the session and automatically hibernates the sandbox after a timeout. You can also hibernate the sandbox explicitly from the server:JavaScript
Pricing
The self-serve option for running the legacy code sandbox is priced according to the CodeSandbox SDK plans, which have two main pricing components:- VM credits: The unit of measurement for VM runtime. One credit equates to a specific amount of resources used per hour, depending on the specs of the VM you are using. VM credits follow a pay-as-you-go approach and are priced at $0.01486 per credit.
- VM concurrency: The maximum number of VMs you can run simultaneously with the SDK. Each CodeSandbox plan has a different VM concurrency limit.
Minutes are the smallest unit of measurement for VM credits. If a VM runs for 3 minutes and 25 seconds, you are billed the equivalent of 4 minutes of VM runtime.
VM credit prices by VM size
The table below summarizes how many VM credits each VM size uses per hour of runtime. The Nano VM size is the default recommendation, as it provides enough resources for most simple workflows. Pico is mostly suitable for very simple code execution jobs.Concurrent VMs
Pick the plan that matches how many concurrent VMs you require:- Build (free) plan: 10 concurrent VMs.
- Scale plan: 250 concurrent VMs.
- Enterprise plan: custom concurrent VMs.
Estimate your bill
To estimate your bill, you must consider:- The base price of your CodeSandbox plan.
- The number of included VM credits on that plan.
- How many VM credits you expect to require.
- You need a Scale plan.
- You use a total of 72,000 VM credits per month (80 VMs x 3 hours/day x 30 days x 10 credits/hour).
- Your Scale plan includes 1,100 free VM credits each month, so you purchase 70,900 VM credits.
- Base price of the Scale plan: $170.
- Total price of VM credits: $1,053.57 (70,900 VM credits x $0.01486 per credit).
- Total bill: $1,223.57.