Skip to content
Sandbox SDK
Esc
↑↓navigate↵open⌘Jpreview
On this page

CLI

Use the sandbox-sdk CLI to check provider setup with doctor, list providers and sandboxes, run commands, exec into existing sandboxes, and start an MCP server.

@opencoredev/sandbox-sdk ships a sandbox-sdk binary with zero extra dependencies. Use it to verify your local environment, run one-off sandbox commands, attach to running sandboxes, or start a stdio MCP server.

Run without installing

npx @opencoredev/sandbox-sdk doctor

Or install it in your project and run npx sandbox-sdk / bunx sandbox-sdk.

Commands

Command Purpose
sandbox-sdk doctor Check Node/Bun version, host tar, Docker reachability, credentials, and optional peer SDKs
sandbox-sdk providers List all built-in providers, peer packages, credential env vars, and readiness
sandbox-sdk run [options] [--] <cmd...> Create a sandbox, run a command, stream output, and clean up
sandbox-sdk exec [options] <id> [--] <cmd...> Connect to an existing sandbox by ID, run a command, and detach without destroying it
sandbox-sdk list [options] List sandboxes created by Sandbox SDK on a provider
sandbox-sdk mcp [options] Serve sandbox tools over MCP stdio (stdout stays protocol-only)

Check your setup

sandbox-sdk doctor
sandbox-sdk doctor --provider e2b --json
sandbox-sdk providers --configured

doctor checks whether optional peer SDKs are resolvable without importing or executing them, recognizes alternative credential sets (such as Daytona’s DAYTONA_API_KEY or DAYTONA_JWT_TOKEN + DAYTONA_ORGANIZATION_ID), and never prints environment variable values. Pass --help after any command (sandbox-sdk run --help, sandbox-sdk mcp --help) for command-specific options. sandbox-sdk mcp handles SIGINT and SIGTERM cleanly even while stdin remains open, destroying ephemeral sandboxes before exit.

Run a command

Pass --provider <name> or set SANDBOX_PROVIDER:

sandbox-sdk run --provider memory "echo hello from sandbox"
sandbox-sdk run --provider e2b --network none -- node -e "console.log(1 + 1)"

Command quoting

  • CLI options must appear before the command; everything after the first command word is passed to the command verbatim (so sandbox-sdk run --provider memory node -v runs node -v without needing --).
  • A single positional argument is passed to the sandbox shell verbatim ("echo hi && pwd").
  • Multiple positional arguments are POSIX-quoted and joined (-- node -e "console.log('a b')"), so spaces and shell metacharacters are preserved safely.

Passing secrets safely

The CLI refuses raw --secret KEY=VALUE flags because command-line arguments are exposed in process listings and shell history. Pass --secret-env NAME instead to read the secret from your host environment and redact it across stdout, stderr, JSON output, and errors:

GITHUB_TOKEN=ghp_example sandbox-sdk run \
  --provider local \
  --secret-env GITHUB_TOKEN \
  "git ls-remote https://github.com/opencoredev/sandbox-sdk.git"

If NAME is unset or empty, the CLI exits immediately with code 2.

Lifecycle flags

  • Without --key or --keep, run destroys the sandbox when the command finishes.
  • With --key <name> or --keep, run calls close(), leaves the sandbox running, and prints Kept sandbox <id> to stderr in plain-text mode (or includes sandboxId in --json). mcp --key and mcp --id also print Kept sandbox <id> to stderr while keeping stdout strictly JSON-RPC.
  • exec <sandbox-id> always calls close() and never destroys the target sandbox.
  • memory and agentos run in-process, so separate CLI invocations cannot reattach to their sandboxes.

List and exec

sandbox-sdk list --provider e2b --label app=builder
sandbox-sdk exec --provider e2b sbx_12345 "ls -la"

Options by command

Global and discovery

  • --provider <name> (doctor, run, exec, list, mcp): provider name; falls back to SANDBOX_PROVIDER for run, exec, list, and mcp (doctor checks all providers when omitted).
  • --json (doctor, providers, run, exec, list): print redacted machine-readable JSON (run and exec include timedOut and aborted booleans).
  • --configured (providers): show only providers whose credentials are configured.
  • --label KEY=VALUE (list): filter sandboxes by label (repeatable).
  • -v, --version (global): print the package version.
  • -h, --help (global or per command): print top-level or command-specific help.

Execution and runtime options

  • --key <key> (run, mcp): get-or-create a keyed sandbox and leave it running on exit.
  • --keep (run): call close() instead of destroy() on exit.
  • --network all|none (run, mcp): sandbox network policy (all by default; rejected with --id or when reusing an existing --key sandbox whose policy cannot be verified).
  • --size small|medium|large (run): machine size preset.
  • --cwd <dir> (run, exec): working directory inside the sandbox (/workspace by default).
  • --env KEY=VALUE (run, exec): environment variable passed to the sandbox or command (repeatable).
  • --timeout-ms <ms> (run, exec, mcp): positive integer timeout in milliseconds (mcp: default timeout for the run tool).
  • --secret-env NAME (run, exec, mcp): read a secret from host env NAME and redact it across stdout, stderr, JSON, and errors (repeatable; raw --secret is rejected).

MCP server (mcp)

  • --id <sandbox-id> (mcp): attach to an existing sandbox instead of creating one (mutually exclusive with --key).
  • --root <dir> (mcp): root directory for file tools (/workspace by default).
  • --allow <t1,t2> (mcp): comma-separated allowlist of MCP tool names.
  • --deny <t1,t2> (mcp): comma-separated denylist of MCP tool names.

Exit codes

Exit code Meaning
0 Command succeeded
2 Invalid CLI usage, unknown flag/command, or missing required credentials / --secret-env for run, exec, list, or mcp
1–255 Non-zero sandbox command exit (run/exec), SDK/provider error (1), output backpressure truncation (1), or failed doctor check (1, e.g. old runtime or --provider not ready)
124 Sandbox command timed out
130 Interrupted (SIGINT / SIGTERM) after sandbox cleanup (waits up to 30 s for any in-flight create to finish and destroy, warning on stderr if cleanup is unconfirmed; a second signal exits immediately)
141 Output pipe closed while streaming (run/exec)

For run and exec, the sandbox command’s own exit code (1–255) is returned directly and can overlap with 2, 124, or 141. Pass --json to inspect result.exitCode, result.timedOut, and result.aborted unambiguously.

Next: MCP integration or Sandbox API.

Was this page helpful?