Sandbox

The object you hold after create() — always-present commands and files namespaces, capability-gated sub-APIs, lifecycle methods, and the raw() escape hatch.

A Sandbox is what client.create() and client.connect() return. It groups everything into namespaces, with capability-gated sub-APIs typed undefined when the provider can't support them.

Members

MemberTypePresence
id / name? / providerstringalways
capabilitiesCapabilitiesalways
commandsCommandsAPIalways (universal)
filesFilesAPIalways (native or polyfilled)
portsPortsAPI | undefinedgated on exposePort
codeCodeAPI | undefinedgated on codeInterpreter
snapshotsSnapshotsAPI | undefinedgated on snapshot
networkNetworkAPI | undefinedgated on egressControl
getInfo / destroy() => Promise<…>always
setTimeout / stop / pause / resume(…) => Promise<void>present, but throw NotSupported where the capability is missing
can<K>(cap: K) => this is Sandbox<…>runtime check + type guard
raw() => Rawthe native client, typed per adapter

Capability gating

ports, code, snapshots, and network are typed undefined on providers that don't support them, so a guard is required — and the absence is caught at compile time:

if (sandbox.code) {
  await sandbox.code.runCode("print(1)");
}

For dynamically-chosen providers, can() narrows at runtime and the type level:

if (sandbox.can("snapshot")) {
  await sandbox.snapshots.create({ name: "ckpt" });
}

See Capabilities for the model, and Escape hatch for raw().

SandboxInfo

Returned by getInfo():

interface SandboxInfo {
  readonly id: string;
  readonly name?: string;
  readonly state: SandboxState; // "creating" | "running" | "paused" | "stopped" | "destroyed" | "error" | "unknown"
  readonly provider: string;
  readonly metadata: Readonly<Record<string, string>>;
  readonly createdAt?: Date;
  readonly raw: unknown; // the original provider payload
}

On this page