freshcrate
Skin:/
Home > Uncategorized > codesandbox-sdk

codesandbox-sdk

Programmatically start (AI) sandboxes on top of CodeSandbox

Why this rank:Strong adoptionHealthy release cadenceRelease freshness

Description

Programmatically start (AI) sandboxes on top of CodeSandbox

README

CodeSandbox SDK

The power of CodeSandbox in a library

CodeSandbox SDK enables you to programmatically spin up development environments and run untrusted code. It provides a programmatic API to create and run sandboxes quickly and securely.

Under the hood, the SDK uses the microVM infrastructure of CodeSandbox to spin up sandboxes. It supports:

  • Snapshotting/restoring VMs (checkpointing) at any point in time
    • With snapshot restore times within 1 second
  • Cloning VMs & Snapshots within 2 seconds
  • Source control (git, GitHub, CodeSandbox SCM)
  • Running any Dockerfile

Check out the CodeSandbox SDK documentation for more information.

Getting Started

To get started, install the SDK:

npm install @codesandbox/sdk

Create an API token by going to https://codesandbox.io/t/api, and clicking on the "Create API Token" button. You can then use this token to authenticate with the SDK:

import { CodeSandbox } from "@codesandbox/sdk";

const sdk = new CodeSandbox(process.env.CSB_API_KEY);
const sandbox = await sdk.sandboxes.create();
const client = await sandbox.connect();

const output = await client.commands.run("echo 'Hello World'");

console.log(output); // Hello World

Efficient Sandbox Retrieval

When you need to retrieve metadata for specific sandboxes by their IDs, you can use the efficient retrieval methods instead of listing and filtering all sandboxes:

Get Single Sandbox

// Efficient single sandbox retrieval
const sandbox = await sdk.sandboxes.get("sandbox-id");
console.log(sandbox.title, sandbox.tags);

This method is significantly more efficient than using list() and filtering, especially for large organizations with thousands of sandboxes.

Configuration

The SDK supports the following environment variables for configuration:

  • CSB_API_KEY: Your CodeSandbox API token for authentication

CodeSandbox Integration

This SDK uses the API token from your workspace in CodeSandbox to authenticate and create sandboxes. Because of this, the sandboxes will be created inside your workspace, and the resources will be billed to your workspace.

Build your own template that has all the dependencies you need (even running servers), and then use that template to create sandboxes from. This way, you can control the environment that the sandboxes run in.

Example Use Cases

These are some example use cases that you could use this library for:

Code interpretation: Run code in a sandbox to interpret it. This way, you can run untrusted code without worrying about it affecting your system.

Development environments: Create a sandbox for each developer, and run their code in the sandbox. This way, you can run multiple development environments in parallel without them interfering with each other.

AI Agents: Create a sandbox for each AI agent, and run the agent in the sandbox. This way, you can run multiple agents in parallel without them interfering with each other.

CI/CD: Run tests inside a sandbox, and hibernate the sandbox when the tests are done. This way, you can quickly start the sandbox again when you need to run the tests again or evaluate the results.

Release History

VersionChangesUrgencyDate
v2.4.2## [2.4.2](https://github.com/codesandbox/codesandbox-sdk/compare/v2.4.1...v2.4.2) (2025-12-04) ### Bug Fixes * send params to restart correctly ([#232](https://github.com/codesandbox/codesandbox-sdk/issues/232)) ([c9775c4](https://github.com/codesandbox/codesandbox-sdk/commit/c9775c43eecdda38b3c7ea309e03610edeb73b0f))Low12/4/2025
v2.4.1## [2.4.1](https://github.com/codesandbox/codesandbox-sdk/compare/v2.4.0...v2.4.1) (2025-10-23) ### Bug Fixes * reconnect issue ([#216](https://github.com/codesandbox/codesandbox-sdk/issues/216)) ([2dfa670](https://github.com/codesandbox/codesandbox-sdk/commit/2dfa670a62d320ffe9b50831e212ede5ae90732d))Low10/23/2025
v2.4.0## [2.4.0](https://github.com/codesandbox/codesandbox-sdk/compare/v2.3.0...v2.4.0) (2025-10-16) ### Infra updates (Agent version `0.369.6`) - Default to `rsync` persistence for both change of remote and nested git - Increase `ulimit` for global user - Do not use `.gitignore` during `rsync` ### Features * batch writes in template build ([#205](https://github.com/codesandbox/codesandbox-sdk/issues/205)) ([9b2f3f6](https://github.com/codesandbox/codesandbox-sdk/commit/9b2f3f66c4a0b3faLow10/16/2025
v2.3.0## [2.3.0](https://github.com/codesandbox/codesandbox-sdk/compare/v2.2.1...v2.3.0) (2025-09-29) ### **History of Hibernation and Persistence** In the original CodeSandbox design, we optimized sandbox lifecycles to feel like cloud-based laptops. When a user stepped away from a project, the sandbox would automatically hibernate after a short period of inactivity. On return, the sandbox would restore almost instantly to its previous state — including memory and persistence. At the time, moLow9/29/2025
v2.2.1## [2.2.1](https://github.com/codesandbox/codesandbox-sdk/compare/v2.2.0...v2.2.1) (2025-09-16) ### Bug Fixes * Throw error when invalid port is used ([#188](https://github.com/codesandbox/codesandbox-sdk/issues/188)) ([d0bdf31](https://github.com/codesandbox/codesandbox-sdk/commit/d0bdf3128787cdea22ea7e18c5af63594c303402))Low9/16/2025
v2.2.0## [2.2.0](https://github.com/codesandbox/codesandbox-sdk/compare/v2.1.0...v2.2.0) (2025-09-02) ### Features * Add traceparent for all requests to API ([#180](https://github.com/codesandbox/codesandbox-sdk/issues/180)) ([b6f4846](https://github.com/codesandbox/codesandbox-sdk/commit/b6f484665de0bf0533127e098ff0ef1aa641a84b)) * batch writes ([#175](https://github.com/codesandbox/codesandbox-sdk/issues/175)) ([493c5d5](https://github.com/codesandbox/codesandbox-sdk/commit/493c5d52d1eaa527d099b0Low9/2/2025
v2.1.0## [2.1.0](https://github.com/codesandbox/codesandbox-sdk/compare/v2.0.7...v2.1.0) (2025-08-22) ### Features * add fetching single sandbox ([#142](https://github.com/codesandbox/codesandbox-sdk/issues/142)) ([2f58d43](https://github.com/codesandbox/codesandbox-sdk/commit/2f58d43ee44c98eeb7d0e917c8b423a80d202585)) * add listRunning method to sandboxes namespace ([#145](https://github.com/codesandbox/codesandbox-sdk/issues/145)) ([6050dbd](https://github.com/codesandbox/codesandbox-sdk/coLow8/22/2025
v2.0.7## [2.0.7](https://github.com/codesandbox/codesandbox-sdk/compare/v2.0.6...v2.0.7) (2025-08-06) ### Bug Fixes * also retry resume ([#143](https://github.com/codesandbox/codesandbox-sdk/issues/143)) ([8b69036](https://github.com/codesandbox/codesandbox-sdk/commit/8b69036d0b586917db05f9c51046ae8b26660835))Low8/6/2025
v2.0.6## [2.0.6](https://github.com/codesandbox/codesandbox-sdk/compare/v2.0.5...v2.0.6) (2025-08-06) ### Bug Fixes * Add retries to all idempotent endpoints and added parallel file writing ([#140](https://github.com/codesandbox/codesandbox-sdk/issues/140)) ([db8aded](https://github.com/codesandbox/codesandbox-sdk/commit/db8aded97e1844cc31f70b08b6a294b458069656)) * Fix broken authorization in preview hosts ([20a4e53](https://github.com/codesandbox/codesandbox-sdk/commit/20a4e538e3b47300778383Low8/6/2025
v2.0.5## [2.0.5](https://github.com/codesandbox/codesandbox-sdk/compare/v2.0.4...v2.0.5) (2025-07-29) ### Bug Fixes * timeout errors on keepActiveWhileConnected ([a519bcf](https://github.com/codesandbox/codesandbox-sdk/commit/a519bcfe86abe2f978718169490a54d9977a9d88))Low7/29/2025
v2.0.4## [2.0.4](https://github.com/codesandbox/codesandbox-sdk/compare/v2.0.3...v2.0.4) (2025-07-16) ### Bug Fixes * fix dependencies ([0211660](https://github.com/codesandbox/codesandbox-sdk/commit/02116601a6f33aa56c465eff63f3d44e2220ccf4)) * move some devdependencies to dependencies ([77f74f1](https://github.com/codesandbox/codesandbox-sdk/commit/77f74f1c81f35c9f9ccd3d159b51857df0b3fc81))Low7/16/2025
v2.0.3## [2.0.3](https://github.com/codesandbox/codesandbox-sdk/compare/v2.0.2...v2.0.3) (2025-07-08) ### Bug Fixes * disable sentry by default, make it optional ([#126](https://github.com/codesandbox/codesandbox-sdk/issues/126)) ([09d9e8a](https://github.com/codesandbox/codesandbox-sdk/commit/09d9e8a9a678c35169f8ff98b6e283fb45e23ed1))Low7/9/2025
v2.0.2## [2.0.2](https://github.com/codesandbox/codesandbox-sdk/compare/v2.0.1...v2.0.2) (2025-07-02) ### Bug Fixes * add api client to runningvms query fn ([0119379](https://github.com/codesandbox/codesandbox-sdk/commit/0119379482320dd1142366838ec0679380800909)) * add apiClient to context and pass to query fn ([75f56da](https://github.com/codesandbox/codesandbox-sdk/commit/75f56dafb1fe93ad395d9727ebab39425875de5d)) * Template resolve files fixes ([#121](https://github.com/codesandbox/codesandbox-sLow7/2/2025
v2.0.1🚀 Features - The template builder now outputs more help to understand template ids and aliases. It also generates a Sandbox from the generated template with a link to the CSB editor for verification <img width="678" alt="Screenshot 2025-07-01 at 11 57 45" src="https://github.com/user-attachments/assets/15787596-cd10-4971-93bb-f33bf9349605" /> 🐛 Bug fixes - The `keepActiveWhileConnected` method now properly sets its state based on the boolean passed. It also handles explicit and impliLow7/1/2025
v2.0.0## đŸ—ī¸ Infra - The Sandbox Agent now detects nested repos and properly persists them when archiving the Sandbox (Requires restart of Sandbox for latest Sandbox Agent) - Fixed a race condition where Sandbox Agent was throwing a false error. Typically happened during template building - We should now send a proper error response from the API, so no more `Internal Server Error` - We have a new internal debug dashboard which allows to more easily debug VM ids across the stack - We have a new stLow6/30/2025
v2.0.0-rc.11## 📝 DOCS You can find the `2.0.0` RC docs at: https://projects-docs-3ubl8mut7-codesandbox1.vercel.app/docs/sdk âš ī¸ **These changes are additional to the previous `rc.10` release!** ## đŸ—ī¸ Infra - The Sandbox Agent now detects nested repos and properly persists them when archiving the Sandbox (Requires restart of Sandbox for latest Sandbox Agent) ## 🚨 Breaking - The `git` namespace has been removed from the Sandbox Client. The reason is that it makes an assumption being used at Low6/27/2025
v2.0.0-rc.10## 📝 DOCS You can find the `2.0.0` RC docs at: https://fsnpxp-3000.csb.app/sdk âš ī¸ **These changes are additional to the previous `rc.9` release!** ## đŸ”Ĩ Hot resizing incident So we identified an issue with what we call "hot resizing sandboxes". This was experienced as VMs not hibernating and also not being able to get them back up. The reason this happened is because Sandboxes where being hot resized below their parent Sandbox tier. Basically the Sandbox goes out of memory. We hLow6/20/2025
v2.0.0-rc.9## 📝 DOCS You can find the `2.0.0` RC docs at: https://fsnpxp-3000.csb.app/sdk âš ī¸ **These changes are additional to the previous `rc.8` release!** ## đŸ—ī¸ Infra - Fixed an issue with scheduling from our Universal Template ## 🚨 Breaking (typing) Finding the correct terminology is always difficult, but we will keep iterating until we get it right: ```ts // This is still considered a Sandbox and represents methods for interacting // with the Sandbox VM. (type: Sandbox) const saLow6/13/2025
v2.0.0-rc.8## 📝 DOCS You can find the `2.0.0` RC docs at: https://fsnpxp-3000.csb.app/sdk ## 🚨 Breaking - The server side SDK and the browser side SDK is now decoupled. Now Node has a much smaller dependency graph and will by default be compatible with edge environments. This did result in certain methods, like `commands.getAll` and `terminals.getAll` to become async - The concept of "sources" is removed. To clone a repository you now create a Sandbox as normal and then use `session.git.clone` Low6/6/2025
v0.12.0## [0.12.0](https://github.com/codesandbox/codesandbox-sdk/compare/v0.11.2...v0.12.0) (2025-04-24) ### Features * add property to check if VM is up to date ([a44c842](https://github.com/codesandbox/codesandbox-sdk/commit/a44c8424dedee731b172ea2cdbbb6fe3ade0f2f5)) * Rest client ([ec8f5eb](https://github.com/codesandbox/codesandbox-sdk/commit/ec8f5ebc8ab5d4e3540b1985a3a98ecfb64b0c7f))Low4/24/2025
v0.11.2## [0.11.2](https://github.com/codesandbox/codesandbox-sdk/compare/v0.11.1...v0.11.2) (2025-04-15) ### Bug Fixes * **build:** consider port opened for faulty status codes ([#84](https://github.com/codesandbox/codesandbox-sdk/issues/84)) ([c5a2469](https://github.com/codesandbox/codesandbox-sdk/commit/c5a246997a07834fe86a73e15762c1e76d552d58))Low4/15/2025
v0.11.1## [0.11.1](https://github.com/codesandbox/codesandbox-sdk/compare/v0.11.0...v0.11.1) (2025-03-13) ### Bug Fixes * support `keepActiveWhileConnected` for browser sessions ([#81](https://github.com/codesandbox/codesandbox-sdk/issues/81)) ([ca1f825](https://github.com/codesandbox/codesandbox-sdk/commit/ca1f82582d2f12b84cdf379902c596e6d5bfed52))Low3/13/2025
v0.11.0## [0.11.0](https://github.com/codesandbox/codesandbox-sdk/compare/v0.10.0...v0.11.0) (2025-03-11) ### Features * add support for configuring auto-wake behaviour ([#79](https://github.com/codesandbox/codesandbox-sdk/issues/79)) ([8c2ef89](https://github.com/codesandbox/codesandbox-sdk/commit/8c2ef897b03ce2d3f4865f6e68e2c2f07824852c))Low3/11/2025
v0.10.0## [0.10.0](https://github.com/codesandbox/codesandbox-sdk/compare/v0.9.0...v0.10.0) (2025-02-28) ### Features * allow defining timeout when waiting for port ([#70](https://github.com/codesandbox/codesandbox-sdk/issues/70)) ([27c559c](https://github.com/codesandbox/codesandbox-sdk/commit/27c559cb36839ba08b8a2518a45a5ede26b44f8b))Low2/28/2025
v0.9.0## [0.9.0](https://github.com/codesandbox/codesandbox-sdk/compare/v0.8.1...v0.9.0) (2025-02-26) ### Features * add support for `--since` when listing sandboxes ([#68](https://github.com/codesandbox/codesandbox-sdk/issues/68)) ([f054205](https://github.com/codesandbox/codesandbox-sdk/commit/f0542057345aa0d11251bba24b9420f1b7ae2574))Low2/26/2025
v0.8.1## [0.8.1](https://github.com/codesandbox/codesandbox-sdk/compare/v0.8.0...v0.8.1) (2025-02-21) ### Bug Fixes * don't use env if not env vars are set ([#66](https://github.com/codesandbox/codesandbox-sdk/issues/66)) ([7b61dcc](https://github.com/codesandbox/codesandbox-sdk/commit/7b61dcc2ba6aa183fb2597674bccd264dbb8615c))Low2/21/2025
v0.8.0## [0.8.0](https://github.com/codesandbox/codesandbox-sdk/compare/v0.7.0...v0.8.0) (2025-02-18) ### Features * support for private previews and preview tokens ([#63](https://github.com/codesandbox/codesandbox-sdk/issues/63)) ([993e509](https://github.com/codesandbox/codesandbox-sdk/commit/993e50981f907f3a2ccf7421a2fd8e4aba96e9cf))Low2/18/2025
v0.7.0## [0.7.0](https://github.com/codesandbox/codesandbox-sdk/compare/v0.6.2...v0.7.0) (2025-02-15) ### Features * add support for passing name and path to cli ([#60](https://github.com/codesandbox/codesandbox-sdk/issues/60)) ([00e8c20](https://github.com/codesandbox/codesandbox-sdk/commit/00e8c201b4dcd55f9ce15fc3bd7db09b7c88a103))Low2/15/2025
v0.6.2## [0.6.2](https://github.com/codesandbox/codesandbox-sdk/compare/v0.6.1...v0.6.2) (2025-02-10) ### Bug Fixes * CommonJS build requires .cjs extension for ESM package ([#56](https://github.com/codesandbox/codesandbox-sdk/issues/56)) ([528022e](https://github.com/codesandbox/codesandbox-sdk/commit/528022e1e6beabd7e91ea755e544bffec02f265e))Low2/10/2025
v0.6.1## [0.6.1](https://github.com/codesandbox/codesandbox-sdk/compare/v0.6.0...v0.6.1) (2025-02-08) ### Performance Improvements * do hibernation and shutdown in parallel ([#54](https://github.com/codesandbox/codesandbox-sdk/issues/54)) ([d8e4c6f](https://github.com/codesandbox/codesandbox-sdk/commit/d8e4c6f54ac91aef526af7ac8207f62f084b159d))Low2/8/2025
v0.6.0## [0.6.0](https://github.com/codesandbox/codesandbox-sdk/compare/v0.5.3...v0.6.0) (2025-02-06) ### Features * allow sandbox to keep active while connected ([#53](https://github.com/codesandbox/codesandbox-sdk/issues/53)) ([7ad63d7](https://github.com/codesandbox/codesandbox-sdk/commit/7ad63d73926a13c7c1d4c23568901f7fd418c899)) * support env and cwd in shell api ([#52](https://github.com/codesandbox/codesandbox-sdk/issues/52)) ([7bf1e35](https://github.com/codesandbox/codesandbox-sdk/commit/7Low2/6/2025
v0.5.3## [0.5.3](https://github.com/codesandbox/codesandbox-sdk/compare/v0.5.2...v0.5.3) (2025-01-30) ### Bug Fixes * use cjs for binary ([#47](https://github.com/codesandbox/codesandbox-sdk/issues/47)) ([7fc76a5](https://github.com/codesandbox/codesandbox-sdk/commit/7fc76a5648f1f2665dfda7c39d1432ca2ae2f768))Low1/30/2025
v0.5.2## [0.5.2](https://github.com/codesandbox/codesandbox-sdk/compare/v0.5.1...v0.5.2) (2025-01-30) ### Bug Fixes * esm node build ([#36](https://github.com/codesandbox/codesandbox-sdk/issues/36)) ([4691813](https://github.com/codesandbox/codesandbox-sdk/commit/46918131508bcf56bde7b0d3f2afb07ae710fec5))Low1/30/2025
v0.5.1## [0.5.1](https://github.com/codesandbox/codesandbox-sdk/compare/v0.5.0...v0.5.1) (2025-01-30) ### Bug Fixes * uploads of big files ([#44](https://github.com/codesandbox/codesandbox-sdk/issues/44)) ([c8e6f46](https://github.com/codesandbox/codesandbox-sdk/commit/c8e6f46299f51f9f8ac3acc5934d34a16e7db051))Low1/30/2025
v0.5.0## [0.5.0](https://github.com/codesandbox/codesandbox-sdk/compare/v0.4.0...v0.5.0) (2025-01-28) ### Features * add more advanced pagination options ([#39](https://github.com/codesandbox/codesandbox-sdk/issues/39)) ([f086bb8](https://github.com/codesandbox/codesandbox-sdk/commit/f086bb88be2cb92848c8b8eae411408028978791)) * list sandboxes by running status ([#37](https://github.com/codesandbox/codesandbox-sdk/issues/37)) ([1e9e19c](https://github.com/codesandbox/codesandbox-sdk/commit/1e9e19c7dLow1/28/2025
v0.4.0## [0.4.0](https://github.com/codesandbox/codesandbox-sdk/compare/v0.3.0...v0.4.0) (2025-01-22) ### Features * support for creating sessions ([#32](https://github.com/codesandbox/codesandbox-sdk/issues/32)) ([491d13d](https://github.com/codesandbox/codesandbox-sdk/commit/491d13db77992df5e3ab3fefb5b9de7e8edbd1c9))Low1/22/2025
v0.3.0## [0.3.0](https://github.com/codesandbox/codesandbox-sdk/compare/v0.2.0...v0.3.0) (2025-01-14) ### Features * add support for listing sandboxes ([#33](https://github.com/codesandbox/codesandbox-sdk/issues/33)) ([6771396](https://github.com/codesandbox/codesandbox-sdk/commit/677139624f95431ec97e12ec985c3545bfe43678))Low1/14/2025
v0.2.0## [0.2.0](https://github.com/codesandbox/codesandbox-sdk/compare/v0.1.0...v0.2.0) (2025-01-10) ### Features * add support for updating hibernation timeout ([#31](https://github.com/codesandbox/codesandbox-sdk/issues/31)) ([efd2051](https://github.com/codesandbox/codesandbox-sdk/commit/efd20510512cfeacc776d47cb0cf5d5563ba2914)) ### Performance Improvements * **build:** precreate files inside sandbox ([#16](https://github.com/codesandbox/codesandbox-sdk/issues/16)) ([6cd070e](https://githubLow1/13/2025
v0.1.0## 0.1.0 (2025-01-09) ### Features * add support for together-ai api token ([af3a023](https://github.com/codesandbox/codesandbox-sdk/commit/af3a0233f1ac8dfae0a0d7cab6b206b4fe1dea5c)) ### Bug Fixes * don't keep VMs alive with polling ([#10](https://github.com/codesandbox/codesandbox-sdk/issues/10)) ([393d53c](https://github.com/codesandbox/codesandbox-sdk/commit/393d53c68bc4ea33983302fc2056727126124fc8)) * include sandbox id in build command ([9a737ea](https://github.com/codesandbox/codesanLow1/9/2025

Dependencies & License Audit

Loading dependencies...

Similar Packages

AutoRedactđŸ›Ąī¸ Redact sensitive information from images securely in your browser with AutoRedact, featuring automatic detection and local processing for privacy.main@2026-06-06
slot-jsx-pragma🎰 Enable declarative slottable components with a custom JSX pragma for seamless React integration and enhanced performance.main@2026-06-06
gh-aw-firewallGitHub Agentic Workflows Firewallv0.25.65
anolisaANOLISA - Agentic Nexus Operating Layer & Interface System Architectureckpt/v0.3.3
omniscientCutting-edge Full-stack AI Platform delivered as a SaaS (Software as a Service). Built on a robust technology stack, integrated with powerful APIs such as OpenAI and Replicate, offers a seamless expermain@2026-06-04

More in Uncategorized

llama.cppLLM inference in C/C++
modal-clientSDK libraries for Modal
anolisaANOLISA - Agentic Nexus Operating Layer & Interface System Architecture