| name | computesdk |
| description | Guide for building sandbox applications with ComputeSDK, a unified TypeScript SDK for running untrusted code in sandboxed environments across multiple compute providers (E2B, Daytona, Vercel, Modal, Railway, Namespace, Render). Use this skill when implementing sandboxed code execution, creating isolated development environments, running LLM-generated code safely, building app builders, or integrating dynamic code execution into applications. |
ComputeSDK
A unified TypeScript SDK for running code in remote sandboxes. Write code once, switch providers by changing environment variables. Supports E2B, Modal, Railway, Daytona, Vercel, Namespace, Render, and more.
Installation
npm install computesdk
Set your credentials:
COMPUTESDK_API_KEY=your_computesdk_api_key
E2B_API_KEY=your_e2b_api_key
Get a ComputeSDK API key at https://console.computesdk.com/register
Quick Start
import { compute } from 'computesdk';
const sandbox = await compute.sandbox.create();
const result = await sandbox.runCode('print("Hello World!")');
console.log(result.output);
await sandbox.destroy();
Sandbox Lifecycle
const sandbox = await compute.sandbox.create({
runtime: 'python',
timeout: 300000,
metadata: { userId: '123' }
});
const existing = await compute.sandbox.getById('sandbox-id');
const named = await compute.sandbox.findOrCreate({
name: 'my-app',
namespace: 'user-alice',
timeout: 30 * 60 * 1000,
});
const found = await compute.sandbox.find({
name: 'my-app',
namespace: 'user-alice',
});
await compute.sandbox.extendTimeout(sandbox.sandboxId);
await sandbox.destroy();
Code Execution
const result = await sandbox.runCode('print("Hello")');
const nodeResult = await sandbox.runCode('console.log("Hi")', 'node');
Command Execution
const result = await sandbox.runCommand('ls -la');
const result = await sandbox.runCommand('npm install', {
cwd: '/app',
env: { NODE_ENV: 'production' },
timeout: 30000,
});
await sandbox.runCommand('npm run dev', { background: true });
await sandbox.runCommand('cd /app && npm install && npm test');
Filesystem
await sandbox.filesystem.writeFile('/app/index.js', 'console.log("hi")');
const content = await sandbox.filesystem.readFile('/app/index.js');
await sandbox.filesystem.mkdir('/app/data');
const files = await sandbox.filesystem.readdir('/app');
const exists = await sandbox.filesystem.exists('/app/index.js');
await sandbox.filesystem.remove('/app/index.js');
await sandbox.file.batchWrite([
{ path: '/app/a.js', content: '...' },
{ path: '/app/b.js', content: '...' },
]);
Managed Servers
Start supervised long-lived processes with install commands, restart policies, health checks, and public URLs.
const server = await sandbox.server.start({
slug: 'web',
install: 'npm install',
start: 'npm run dev',
path: '/app',
port: 3000,
restart_policy: 'on-failure',
max_restarts: 5,
health_check: {
path: '/',
interval_ms: 5000,
timeout_ms: 3000,
},
environment: {
NODE_ENV: 'development',
},
});
console.log(server.status);
console.log(server.url);
const servers = await sandbox.server.list();
const info = await sandbox.server.retrieve('web');
await sandbox.server.restart('web');
await sandbox.server.stop('web');
const logs = await sandbox.server.logs('web');
Create servers inline with sandbox creation:
const sandbox = await compute.sandbox.create({
servers: [{
slug: 'dev',
install: 'npm install',
start: 'npm run dev',
path: '/app',
health_check: { path: '/' },
}],
});
Overlays (Template Mounting)
Bootstrap sandboxes from template directories instantly.
const overlay = await sandbox.filesystem.overlay.create({
source: '/templates/nextjs',
target: './project',
strategy: 'smart',
ignore: ['.git', '*.log'],
waitForCompletion: true,
});
const overlay = await sandbox.filesystem.overlay.create({
source: '/templates/react',
target: './app',
});
await sandbox.filesystem.overlay.waitForCompletion(overlay.id);
Combine overlays with servers:
const sandbox = await compute.sandbox.create({
overlays: [{
source: '/templates/nextjs',
target: './project',
strategy: 'smart',
}],
servers: [{
slug: 'dev',
install: 'npm install',
start: 'npm run dev',
path: './project',
health_check: { path: '/' },
}],
});
Terminals
const terminal = await sandbox.terminal.create({ pty: true });
terminal.write('ls -la\n');
terminal.on('data', (data) => console.log(data));
terminal.resize({ cols: 120, rows: 40 });
const exec = await sandbox.terminal.create({ pty: false });
Client Access (Browser Delegation)
Delegate sandbox access to browser clients without exposing API keys.
const token = await sandbox.sessionToken.create({
expiresIn: 3600,
});
import { Sandbox } from 'computesdk';
const clientSandbox = await Sandbox.connect({ url, token: token.token });
const link = await sandbox.magicLink.create({
redirectUrl: 'https://myapp.com/editor',
});
Provider Configuration
Auto-detection from environment variables is recommended. All providers also require COMPUTESDK_API_KEY.
| Provider | Environment Variables |
|---|
| E2B | E2B_API_KEY |
| Modal | MODAL_TOKEN_ID, MODAL_TOKEN_SECRET |
| Railway | RAILWAY_API_KEY, RAILWAY_PROJECT_ID, RAILWAY_ENVIRONMENT_ID |
| Daytona | DAYTONA_API_KEY |
| Vercel | VERCEL_TOKEN, VERCEL_TEAM_ID, VERCEL_PROJECT_ID |
| Namespace | NSC_TOKEN |
| Render | RENDER_API_KEY, RENDER_OWNER_ID |
Detection order: E2B -> Railway -> Daytona -> Modal -> Runloop -> Vercel -> Cloudflare -> CodeSandbox
For explicit configuration:
compute.setConfig({
computesdkApiKey: process.env.COMPUTESDK_API_KEY,
provider: 'e2b',
e2b: { apiKey: process.env.E2B_API_KEY }
});
Switch providers at runtime:
compute.setConfig({
computesdkApiKey: 'key',
provider: 'e2b',
e2b: { apiKey: process.env.E2B_API_KEY }
});
const e2bSandbox = await compute.sandbox.create();
compute.setConfig({
computesdkApiKey: 'key',
provider: 'modal',
modal: {
tokenId: process.env.MODAL_TOKEN_ID,
tokenSecret: process.env.MODAL_TOKEN_SECRET
}
});
const modalSandbox = await compute.sandbox.create();
Multiple Compute Instances
import { compute, createCompute } from 'computesdk';
const sandbox = await compute.sandbox.create();
const compute1 = createCompute();
const compute2 = createCompute();
Sandbox Info
const info = await sandbox.getInfo();
TypeScript Types
import type {
Sandbox,
SandboxInfo,
CodeResult,
CommandResult,
CreateSandboxOptions
} from 'computesdk';
Provider-Specific Skills
For provider-specific setup guides, install these skills:
npx skills add https://github.com/computesdk/sandbox-skills --skill e2b-sandbox
npx skills add https://github.com/computesdk/sandbox-skills --skill vercel-sandbox
npx skills add https://github.com/computesdk/sandbox-skills --skill daytona-sandbox
npx skills add https://github.com/computesdk/sandbox-skills --skill modal-sandbox
npx skills add https://github.com/computesdk/sandbox-skills --skill railway-sandbox
npx skills add https://github.com/computesdk/sandbox-skills --skill namespace-sandbox
npx skills add https://github.com/computesdk/sandbox-skills --skill render-sandbox
e2b-sandbox — E2B Firecracker microVMs, sub-second cold starts
vercel-sandbox — Globally distributed serverless execution
daytona-sandbox — Full development workspace environments
modal-sandbox — GPU-accelerated execution for ML workloads
railway-sandbox — Self-hosted sandboxes on Railway infrastructure
namespace-sandbox — Custom CPU/RAM allocation, architecture control
render-sandbox — Self-hosted sandboxes with zero infrastructure setup
References