SDK
Introduction

CodeSandbox SDK

Programmatically spin up (AI) sandboxes

CodeSandbox SDK enables you to quickly create and run isolated sandboxes securely. The SDK can be used to run concurrent VMs to support multiple use cases such as browser editors, AI agents, code interpretation and more

Getting Started

  1. Create or log into your CodeSandbox account (opens in a new tab)

  2. Next create an API key at https://codesandbox.io/t/api (opens in a new tab), and enable all scopes.

  3. Install the SDK:

npm install @codesandbox/sdk

Your first interaction:

import { CodeSandbox } from "@codesandbox/sdk";
 
const sdk = new CodeSandbox(process.env.CSB_API_KEY!);
 
const sandbox = await sdk.sandboxes.create();
 
const session = await sandbox.connect();
 
const output = await session.commands.run("echo 'Hello World'");
 
console.log(output) // Hello World

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.

Under the hood, the SDK uses CodeSandbox's microVM infrastructure to spin up sandboxes. The environment supports:

  1. Resume/clone VMs in under 1 second
  2. VM FS persistence (with git version control)
  3. Environment customization using Docker & Docker Compose (Dev Containers)