sandbox.exec.sandbox.exec.run(command, opts?)body commandstringrequiredbody timeoutnumberdefault: 60body envRecord<string, string>body cwdstringPromise<ProcessResult>1const result = await sandbox.exec.run("npm test", { cwd: "/app" });
sandbox.exec.start(command, opts?)body commandstringrequiredbody argsstring[]body envRecord<string, string>body cwdstringbody timeoutnumberbody maxRunAfterDisconnectnumberbody onStdout(data: Uint8Array) => voidbody onStderr(data: Uint8Array) => voidbody onExit(exitCode: number) => voidPromise<ExecSession>123const session = await sandbox.exec.start("node server.js", { onStdout: (data) => process.stdout.write(data), });
sandbox.exec.background(command, opts?)start. Same options, same return type. Use when the intent is "run this in the background and observe it" — more discoverable than start for that case.1234const server = await sandbox.exec.background("npm", { args: ["run", "dev"], onStdout: (data) => process.stdout.write(data), });
sandbox.exec.shell(opts?).run() calls share the same bash process, so cwd, exported env vars, and shell functions persist — the ergonomics of a terminal tab.bash --noprofile --norc session. Foreground-only: concurrent .run() rejects with ShellBusyError. Use background for fire-and-forget processes.body cwdstringbody envRecord<string, string>Promise<Shell>12345678910const sh = await sandbox.exec.shell({ cwd: "/app" }); await sh.run("npm install"); await sh.run("export NODE_ENV=test"); const r = await sh.run("npm test", { onStdout: (b) => process.stdout.write(b), }); console.log(r.exitCode); await sh.close();
| Member | Type | Description |
sessionId | string | Underlying exec session ID |
run(cmd, opts?) | Promise<ProcessResult> | Run a command, blocking until it exits |
close() | Promise<void> | Write exit and wait for bash to terminate |
| Parameter | Type | Description |
onStdout | (data: Uint8Array) => void | Per-call stdout callback |
onStderr | (data: Uint8Array) => void | Per-call stderr callback |
cwd, env, and timeout are intentionally not supported in v1. Use inline shell syntax (cd /x && cmd, FOO=bar cmd) — the shell state carries across calls. Timeouts will land once we have a "signal foreground job" primitive.ShellBusyError — another run() is in flight (shell is foreground-only).ShellClosedError — bash has exited (explicit close(), a command ran exit, or the session dropped).sandbox.exec.attach(sessionId, opts?)body sessionIdstringrequiredbody onStdout(data: Uint8Array) => voidbody onStderr(data: Uint8Array) => voidbody onExit(exitCode: number) => voidbody onScrollbackEnd() => voidPromise<ExecSession>sandbox.exec.kill(sessionId, signal?)9 (SIGKILL). HTTP API →Promise<void>| Member | Type | Description |
sessionId | string | Session ID |
done | Promise<number> | Resolves with exit code |
sendStdin(data) | method | Send input (string or Uint8Array) |
kill(signal?) | Promise<void> | Kill process |
close() | method | Close WebSocket |
12345interface ProcessResult { exitCode: number; stdout: string; stderr: string; }
12345678910interface ExecSessionInfo { sessionID: string; sandboxID: string; command: string; args: string[]; running: boolean; exitCode?: number; startedAt: string; attachedClients: number; }