Documentation Index
Fetch the complete documentation index at: https://docs.superserve.ai/llms.txt
Use this file to discover all available pages before exploring further.
run() starts a command and gives you the result once it finishes. spawn() is for when you need to stay connected while it runs: send it input, signal it, and read its output as it arrives. You get back a session and keep it until the process exits.
In Python,
spawn() is on AsyncSandbox only; the synchronous Sandbox.commands.spawn() raises and points you there. In TypeScript it works in the browser and in Node 22+. Older Node needs a WebSocket polyfill such as ws.When to use which
Most of the time you wantrun(): scripts, builds, anything that takes its input up front and hands back output. Switch to spawn() when the process reads from stdin, when you need to signal it, or when you’re streaming an agent’s output and feeding it more as it goes.
run() | spawn() | |
|---|---|---|
| Gives you | the result, once it finishes | a session, while it runs |
| Stdin | none | stdin.write(), stdin.close() |
| Signals | none | kill() |
The session
spawn() resolves once the process is running and hands back a session:
stdin.write(data)takes a string or raw bytes.stdin.close()sends EOF, which programs likecator a REPL wait for before they finish.kill(signal)sends a signal,SIGTERMby default.wait()resolves with the result when the process exits.- Wrap the session in
await using(TypeScript) orasync with(Python) and it kills the process and closes the connection when the block ends.
If the connection drops
wait() fails if the socket closes before the command finishes. The process keeps running inside the sandbox, so save the ID and pick it back up with Sandbox.connect(id). A paused sandbox wakes on its own before the session opens.