CodeSandbox SDK

Security & Safety 💻 TypeScript 🟡 Quiet lately
111 stars

CodeSandbox SDK is a JavaScript library that lets you programmatically create and manage sandboxes—secure, isolated development environments powered by CodeSandbox's microVM infrastructure. It solves the problem of running untrusted code or managing reproducible environments by providing a simple API to spin up, snapshot, clone, and run commands in sandboxes. It is for developers building tools like AI agents, CI/CD pipelines, or multi-tenant development platforms.

✨ Key features

  • Create and connect to sandboxes programmatically
  • Snapshot and restore VMs in under 1 second
  • Clone VMs and snapshots within 2 seconds
  • Support for git, GitHub, and CodeSandbox SCM
  • Run any Dockerfile in the sandbox
  • Efficient retrieval of sandbox metadata by ID

🎯 Use cases

  • Run untrusted code in an isolated environment
  • Create per-developer development environments
  • Run AI agents in separate sandboxes
  • Execute CI/CD tests in sandboxes with hibernation

📦 Installation

🧰 Requirements: Requires Node.js and a CodeSandbox API token (CSB_API_KEY) from https://codesandbox.io/t/api.

npm install @codesandbox/sdk

🚀 Usage

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

⚠️ Good to know

Sandboxes are created within your CodeSandbox workspace and billed to it; the SDK is not self-hosted and requires a CodeSandbox account.

❓ FAQ

How do I authenticate with the SDK?

You need to create an API token at https://codesandbox.io/t/api and set it as the CSB_API_KEY environment variable or pass it to the CodeSandbox constructor.

Can I use my own Dockerfile?

Yes, the SDK supports running any Dockerfile, allowing you to customize the sandbox environment.

How fast are snapshot restores?

Snapshot restore times are within 1 second, and cloning VMs or snapshots takes within 2 seconds.

Are sandboxes billed to my workspace?

Yes, sandboxes are created inside your CodeSandbox workspace and resources are billed to that workspace.

📊 Repository

Stars★ 111
Forks🍴 40
Open issues🐛 25
Last commit🕒 Jun 18, 2026
Created📅 Dec 2024
Language💻 TypeScript

🤖 Overview, features, install steps and FAQ were generated from the project's README on Sep 4, 2026. Always check the original source before running commands.