Managed processes
Keep servers, builds, and interactive programs running after a request finishes.
Last updated
Managed processes keep running after the request returns. Use them for servers,
builds, watchers, and REPLs. Use exec for a command that should finish
as part of one request.
Start a process
Start the program, then keep its handle to check it, read its output, or stop it later.
const proc = await sandbox.process.start({
cmd: ["npm", "run", "dev"],
cwd: "/workspace",
});
for await (const event of proc.stream()) {
if (event.type === "stdout") process.stdout.write(event.text);
if (event.type === "exit") break;
}You can also start a process with the Python SDK or raw HTTP. See the TypeScript SDK, Python SDK, or the API reference for the complete request shape.
Work with it
With the returned handle you can:
- read or stream output;
- send input, including EOF for programs that wait for it;
- wait for completion and inspect the exit code;
- send a graceful signal or stop the process; and
- reconnect later from another client.
Set pty: true when the program needs an interactive terminal. A PTY process
can receive keystrokes and resize events; use the terminal for a
short-lived interactive shell instead.
What to expect
- The process outlives the starting request and can be reconnected to while the sandbox stays running.
- Output is buffered for reading and streaming. Consume important output while the process runs; it is not durable storage.
- Deleting a sandbox ends its managed processes. A stop keeps them when the
start restores memory (
restore: "memory"). When the start cold-boots the disk (restore: "disk_only"), they are gone. Checkrestoreon the start response; see What a start restored. - Processes started with
execare one-shot and do not remain available after the call; start a managed process for long-lived work.
For request and response fields, limits, status codes, and recovery behavior, use the API reference.
See also
- Processes & code execution — one-shot commands and code
- Terminal — an interactive shell
- Run Docker in a sandbox —
dockerdas a managed process, Compose stacks that survive a stop - Filesystem — read, write, and search files