The official JavaScript/TypeScript SDK for Sandbox0, providing typed models and ergonomic high-level APIs for managing secure code execution sandboxes.
npm install sandbox0
# or
yarn add sandbox0
# or
pnpm add sandbox0- Node.js 18.0.0 or later
Streaming APIs prefer a runtime-native globalThis.WebSocket when a Node-compatible host exposes one, and fall back to the ws package on older Node runtimes. This keeps the main SDK entry compatible with SandFunc-style runtimes that expose a standard outbound WebSocket client without requiring raw socket access in user code.
| Environment Variable | Required | Default | Description |
|---|---|---|---|
SANDBOX0_TOKEN |
Yes | - | API authentication token |
SANDBOX0_BASE_URL |
No | https://api.sandbox0.ai |
API base URL |
import { Client } from "sandbox0";
const client = new Client({
token: process.env.SANDBOX0_TOKEN!,
});
async function main() {
// Claim a sandbox
const sandbox = await client.sandboxes.claim("default");
try {
// Execute Python code (REPL - stateful)
const result = await sandbox.run("python", "print('Hello, Sandbox0!')");
process.stdout.write(result.outputRaw);
} finally {
// Cleanup
await client.sandboxes.delete(sandbox.id);
}
}
main().catch(console.error);const stream = await sandbox.cmdStream("sh -c 'echo hello && echo warn >&2'", {
command: ["sh", "-c", "echo hello && echo warn >&2"],
});
for await (const output of stream.outputs()) {
process.stdout.write(output.data);
}
const done = await stream.wait();
console.log(`exit=${done.exitCode} state=${done.state}`);const volume = await client.volumes.create({});
const sandbox = await client.sandboxes.claim("default", {
mounts: [{ sandboxvolumeId: volume.id, mountPoint: "/workspace/data" }],
});
for (const mount of sandbox.bootstrapMounts) {
console.log(mount.sandboxvolumeId, mount.state);
}Apache-2.0