- Memory snapshot/restore (checkpointing) at any point in time
- Resume/clone VMs from a snapshot in 3 seconds
- VM FS persistence (with git version control)
- Environment customization using Docker & Docker Compose (Dev Containers)
Accessing Together Code Sandbox
Code Sandbox is a Together product that is currently available on our custom plans.A self-serve option is possible by creating an account with CodeSandbox.
📌 About CodeSandbox.io CodeSandbox is a Together company that is in process of migrating all relevant products to the Together platform. In the coming months, all Code Sandbox features will be fully migrated into your Together account. Note that Together Code Sandbox is referred to as the SDK within the CodeSandbox.io
Getting Started
To get started, install the SDK:Text
TypeScript
Sandbox life-cycle
By default a Sandbox will be created from a template. A template is a memory/fs snapshot of a Sandbox, meaning it will be 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 access itsbootupType
. This value indicates how the Sandbox was started.
FORK: The Sandbox was created from a template. This happens when you call create
successfully.RUNNING: The Sandbox was already running. This happens when you call
resume
and the Sandbox was already running.RESUME: The Sandbox was resumed from hibernation. This happens when you call
resume
and the Sandbox was hibernated.CLEAN: The Sandbox was created or resumed from scratch. This happens when you call
create
or resume
and the Sandbox was not running and was missing a snapshot. This can happen if the Sandbox was shut down, restarted, the snapshot was expired (old snapshot) or if something went wrong.
Managing CLEAN bootups
Whenever we boot a sandbox from scratch, we’ll:- Start the Firecracker VM
- Create a default user (called pitcher-host)
- (optional) Build the Docker image specified in the .devcontainer/devcontainer.json file
- Start the Docker container
- Mount the /project/sandbox directory as a volume inside the Docker container
JavaScript
Using templates
Code Sandbox has default templates that you can use to create sandboxes. These templates are available in the Template Library and by default we use the “Universal” template. To create your own template you will need to use our CLI.Creating the template
Create a new folder in your project and add the files you want to have available inside your Sandbox. For example set up a Vite project:Text
JSON
setupTasks
will run after the Sandbox has started, before any other tasks.
Now we are ready to deploy the template to our clusters, run:
Text
Note
The template will by default be built with Micro VM Tier unless you pass —vmTier to the build command.JavaScript
Connecting Sandboxes in the browser
In addition to running your Sandbox in the server, you can also connect it to the browser. This requires some collaboration with the server.JavaScript
JavaScript
onFocusChange
and by default it will reconnect when the page is visible.
JavaScript
connectToSandbox
promise is resolving you can also listen to initialization events to show a loading state:
JavaScript
Disconnecting the Sandbox
Disconnecting the session will end the session and automatically hibernate the sandbox after a timeout. You can also hibernate the sandbox explicitly from the server.JavaScript
Pricing
The self-serve option for running Code Sandbox is priced according to the CodeSandbox SDK plans which follows two main pricing components: VM credits: Credits serve as 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. Learn more about credits here. VM concurrency: This defines the maximum number of VMs you can run simultaneously with the SDK. As explored below, each CodeSandbox plan has a different VM concurrency limit.Note
We use minutes as the smallest unit of measurement for VM credits. E.g.: if a VM runs for 3 minutes and 25 seconds, we bill the equivalent of 4 minutes of VM runtime.VM credit prices by VM size
Below is a summary of how many VM credits are used per hour of runtime in each of our available VM sizes. Note that, by default, we recommend using the Nano VM size, as it should provide enough resources for most simple workflows (Pico is mostly suitable for very simple code execution jobs) .VM size | Credits / hour | Cost / hour | CPU | RAM |
---|---|---|---|---|
Pico | 5 credits | $0.0743 | 2 cores | 1 GB |
Nano | 10 credits | $0.1486 | 2 cores | 4 GB |
Micro | 20 credits | $0.2972 | 4 cores | 8 GB |
Small | 40 credits | $0.5944 | 8 cores | 16 GB |
Medium | 80 credits | $1.1888 | 16 cores | 32 GB |
Large | 160 credits | $2.3776 | 32 cores | 64 GB |
XLarge | 320 credits | $4.7552 | 64 cores | 128 GB |
Concurrent VMs
To pick the most suitable plan for your use case, consider how many concurrent VMs you require and pick the corresponding plan:- Build (free) plan: 10 concurrent VMs
- Scale plan: 250 concurrent VMs
- Enterprise plan: custom concurrent VMs
For enterprise
Please contact SalesEstimating 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 will need a Scale plan (which allows up to 100 concurrent VMs).
- You will 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 1100 free VM credits each month, so you will purchase 70,900 VM credits (72,000 - 1100).
- Base price of Scale plan: $170
- Total price of VM credits: 0.01486/credit)
- Total bill: $1223.57