sandbox.exec.await sandbox.exec.run(command, ...)sh -c. HTTP API →body commandstrrequiredbody timeoutintdefault: 60body envdict[str, str]body cwdstrProcessResult1result = await sandbox.exec.run("npm test", cwd="/app")
await sandbox.exec.start(command, ...)body commandstrrequiredbody argslist[str]body envdict[str, str]body cwdstrbody timeoutintbody max_run_after_disconnectintbody on_stdoutCallable[[bytes], None]body on_stderrCallable[[bytes], None]body on_exitCallable[[int], None]ExecSession123456session = await sandbox.exec.start( "node", args=["server.js"], cwd="/app", on_stdout=lambda b: print(b.decode(), end=""), on_exit=lambda code: print(f"exited {code}"), ) exit_code = await session.done
await sandbox.exec.background(command, ...)start. Same signature, same return type. Use when the intent is "run this in the background and observe it".1server = await sandbox.exec.background("npm", args=["run", "dev"])
await sandbox.exec.shell(...).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() raises ShellBusyError.body cwdstrbody envdict[str, str]Shell12345678sh = await sandbox.exec.shell(cwd="/app") await sh.run("npm install") await sh.run("export NODE_ENV=test") r = await sh.run("npm test", on_stdout=lambda b: print(b.decode(), end="")) print(r.exit_code) await sh.close()
| Member | Type | Description |
session_id | str | Underlying exec session ID |
run(cmd, on_stdout=?, on_stderr=?) | ProcessResult | Run a command, blocking until it exits |
close() | None | Write exit and wait for bash to terminate |
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.ShellBusyError — another run() is in flight (shell is foreground-only).ShellClosedError — bash has exited (explicit close(), a command ran exit, or the session dropped).await sandbox.exec.attach(session_id, ...)body session_idstrrequiredbody on_stdoutCallable[[bytes], None]body on_stderrCallable[[bytes], None]body on_exitCallable[[int], None]body on_scrollback_endCallable[[], None]ExecSession| Member | Type | Description |
session_id | str | Session ID |
done | asyncio.Future[int] | Resolves with exit code |
send_stdin(data) | coroutine | Send input (str or bytes) |
kill(signal=9) | coroutine | Kill process |
close() | coroutine | Detach WebSocket (process keeps running) |
12345@dataclass class ProcessResult: exit_code: int stdout: str stderr: str
12345678910@dataclass class ExecSessionInfo: session_id: str sandbox_id: str command: str args: list[str] running: bool exit_code: int | None started_at: str attached_clients: int