Sandbox SDK
API Reference

Sandboxes

Create normalized sandboxes and access their shared surface.

Creating a sandbox

sandbox.ts
await using sandbox = await createSandbox({
  provider,
  cwd: "/workspace",
  env: { NODE_ENV: "development" },
  timeout: 300_000,
  signal: abortController.signal,
});
OptionTypeDefaultBehavior
providerSandboxProviderRequiredAdapter used to create the runtime.
cwdstring/workspaceAbsolute working directory for normalized paths and commands.
envRecord<string, string>{}Environment variables passed during creation.
timeoutnumberProvider defaultCreation timeout in milliseconds.
signalAbortSignalNoneCancels creation when supported by the provider.

cwd must be absolute and cannot contain a null byte.

Sandbox implements Symbol.asyncDispose. The await using declaration calls sandbox.stop() when the enclosing block, function, or module exits, including when an operation throws.

Node.js 24 and Bun run await using directly. TypeScript 5.2 or newer can compile it for Node.js 22 when the target is ES2022. Use withSandbox() when running uncompiled JavaScript on Node.js 22.

tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "lib": ["ES2022", "ESNext.Disposable", "DOM"]
  }
}

Sandbox properties

PropertyTypeDescription
idstringProvider or adapter identifier for this sandbox.
providerProviderNamelocal, e2b, daytona, vercel, upstash, box, or railway.
cwdstringNormalized working directory.
capabilitiesCapabilityMapSupported operations and their modes.
rawProvider-native typeTyped access to the underlying provider SDK object.

Automatic cleanup

Keep sandbox work inside the await using scope. The sandbox is stopped after the final statement.

task.ts
{
  await using sandbox = await createSandbox({ provider });
  await sandbox.run("bun test");
} // sandbox.stop() is awaited here

Do not return the sandbox from that scope because it has already stopped. Create it without await using only when another scope must own its lifecycle.

Manual cleanup

sandbox.ts
const sandbox = await createSandbox({ provider });

try {
  await sandbox.run("bun test");
} finally {
  await sandbox.stop();
}

stop() is idempotent, so repeated calls share the same cleanup operation.

Callback compatibility

withSandbox() remains available for applications that already use callback-scoped cleanup or run uncompiled JavaScript on Node.js 22. It returns the callback result after stopping the sandbox.

legacy-task.ts
const result = await withSandbox({ provider }, async (sandbox) => {
  return sandbox.run("bun test");
});

Write files or run commands.

On this page