API Reference

Sandbox Bindings

API reference for sandbox bindings — vercelSandbox(), localSandbox(), dockerSandbox() — and the SandboxInstance interface.

Sandbox bindings are passed to agent("my-agent", { sandbox: ... }) to configure where tools execute. Import them from experimental-agent/sandbox.

import { vercelSandbox, localSandbox, dockerSandbox } from "experimental-agent/sandbox";

const myAgent = agent("my-agent", {
  sandbox: vercelSandbox(),
});

When no sandbox is provided, the SDK auto-detects the best binding:

  1. Vercel — if running on Vercel (VERCEL_OIDC_TOKEN is set)
  2. Docker — if docker sandbox CLI is available
  3. Local — fallback

You can also pass an array of bindings and select one at setup time via type:

const myAgent = agent("my-agent", {
  sandbox: [vercelSandbox(), localSandbox()],
});

const sb = myAgent.sandbox();
await sb.setup({ type: "vercel" });

vercelSandbox(defaults?)

import { vercelSandbox } from "experimental-agent/sandbox";

Vercel Sandbox with full Node.js and Python runtime, filesystem, and network.

Factory defaults

All binding factories accept optional defaults that are applied automatically during setup. Options passed to .setup() override these defaults.

ParameterTypeDescription
versionstringSetup version string for snapshot invalidation.
run(sandbox: SandboxInstance) => Promise<void>One-time setup function.
configVercelBindingConfigBinding-specific config (see below).
networkPolicyNetworkPolicyNetwork access rules.
const myAgent = agent("my-agent", {
  sandbox: vercelSandbox({
    version: "v1",
    run: async (sandbox) => {
      await sandbox.exec({ command: "npm", args: ["install"] });
    },
    config: { ports: [3000] },
  }),
});

VercelBindingConfig

Passed via config in the factory defaults or sandbox.setup({ config: { ... } }):

ParameterTypeDefaultDescription
cwdstring"/home/vercel-sandbox"Working directory inside the sandbox.
resources{ vcpus: number }{ vcpus: 2 }CPU resources.
portsnumber[]Ports to expose publicly.
networkPolicyNetworkPolicyNetwork access rules.
snapshotIdstringResume from a specific snapshot.
lifecycleLifecycleConfigLifecycle management settings.

LifecycleConfig:

ParameterTypeDescription
pollIntervalMsnumberPolling interval for status checks.
stopAfterInactiveMsnumberStop sandbox after inactivity.
snapshotBeforeTimeoutMsnumberSnapshot before timeout.

NetworkPolicy: "allow-all" | "deny-all" | { allow?: string[]; subnets?: { allow?: string[]; deny?: string[] } }

  • "allow-all" — Full network access.

  • "deny-all" — No network access.

  • { allow: string[] } — Allow specific domains (e.g. ["github.com", "*.github.com"]).

  • { subnets: { allow?: string[]; deny?: string[] } } — Subnet-level rules.

const myAgent = agent("my-agent", {
  sandbox: vercelSandbox(),
});

const sb = myAgent.sandbox("my-sandbox");
await sb.setup({
  type: "vercel",
  version: "dev-env-v3",
  config: {
    ports: [3000],
    networkPolicy: { allow: ["github.com", "*.github.com"] },
  },
  run: async (sandbox) => {
    await sandbox.exec({ command: "npm", args: ["install"] });
  },
});

localSandbox(defaults?)

import { localSandbox } from "experimental-agent/sandbox";

Host filesystem sandbox. Tools execute directly on your machine. Great for development. Accepts the same factory defaults as vercelSandbox().

LocalBindingConfig

ParameterTypeDefaultDescription
cwdstringprocess.cwd()Working directory.
const myAgent = agent("my-agent", {
  sandbox: localSandbox(),
});

dockerSandbox(defaults?)

import { dockerSandbox } from "experimental-agent/sandbox";

Docker container sandbox. Provides isolation without cloud dependencies. Requires Docker Desktop with Docker Sandboxes enabled. Accepts the same factory defaults as vercelSandbox().

DockerBindingConfig

ParameterTypeDefaultDescription
cwdstring"/home/agent/workspace"Working directory inside the container.
const myAgent = agent("my-agent", {
  sandbox: dockerSandbox(),
});

SandboxInstance

The sandbox instance is available inside setup.run, and via ctx.sandbox in ToolContext.

sandbox.exec(opts)

Execute a shell command in the sandbox.

ParameterTypeRequiredDescription
commandstringYesCommand to run (e.g. "npm", "bash").
argsstring[]NoCommand arguments.
cwdstringNoWorking directory for the command.
envRecord<string, string>NoEnvironment variables.
sudobooleanNoRun as root.
signalAbortSignalNoAbortSignal to cancel the command.

Returns: Promise<ExecResult>

type ExecResult = {
  commandId: string;
  logs: () => AsyncIterable<{ stream: "stdout" | "stderr"; data: string }>;
  result: Promise<{ stdout: string; stderr: string; exitCode: number }>;
};
const result = await sandbox.exec({ command: "npm", args: ["run", "test"] });
const { stdout, stderr, exitCode } = await result.result;

sandbox.readFile(opts)

Read a file from the sandbox.

ParameterTypeDescription
pathstringPath relative to workspace root.
signalAbortSignalAbortSignal to cancel.

Returns: Promise<Buffer | null> — File contents, or null if not found.

sandbox.writeFiles(opts)

Write files to the sandbox.

ParameterTypeDescription
filesUploadableFile[]Array of { path: string; content: string | Buffer }.
destPathstringDestination directory.
signalAbortSignalAbortSignal to cancel.

Returns: Promise<void>

sandbox.getDomain(opts)

Get the public domain URL for an exposed port. Returns http://localhost:<port> for local and Docker sandboxes.

ParameterTypeDescription
portnumberPort number.
signalAbortSignalAbortSignal to cancel.

Returns: Promise<string>

sandbox.kill(opts)

Kill a running command.

ParameterTypeDescription
commandIdstringFrom ExecResult.commandId.
signalAbortSignalAbortSignal to cancel.

Returns: Promise<void>

sandbox.updateNetworkPolicy(opts)

Dynamically update network policy. Only supported on Vercel sandboxes.

ParameterTypeDescription
policyNetworkPolicy"allow-all", "deny-all", or { allow: string[] }.
signalAbortSignalAbortSignal to cancel.

Returns: Promise<NetworkPolicy>

await sandbox.updateNetworkPolicy({ policy: { allow: ["github.com"] } });
await sandbox.updateNetworkPolicy({ policy: "deny-all" });

sandbox.start(opts?)

Start the sandbox.

Returns: Promise<void>

sandbox.stop(opts?)

Stop the sandbox. Not supported on local sandboxes.

Returns: Promise<void>

sandbox.snapshot(opts?)

Create a snapshot for fast resume. Only supported on Vercel sandboxes.

Returns: Promise<{ snapshotId: string }>

sandbox.getStatus(opts?)

Get the current sandbox status.

Returns: Promise<"pending" | "running" | "stopping" | "stopped" | "failed">

See also