commands.run, which waits for the process
to exit before returning output, stdio lets you:
- Send input line by line — pipe data into
cat,wc,jq, a database CLI, or any process that reads from stdin interactively. - Receive output as it arrives — via callbacks or an iterator, not as one blob at the end.
- Separate stdout and stderr — independent callbacks for each stream.
- Close stdin to signal EOF — the process sees end-of-file on its stdin, just like pressing Ctrl-D in a terminal.
- Kill long-running processes — terminate a process mid-execution and retrieve the exit code.
When to use Stdio vs Commands vs PTY
Use commands.run when… | Use stdio.start when… | Use pty.create when… |
|---|---|---|
| Command takes all input upfront and exits | Command reads from stdin interactively | Command needs a real terminal (ANSI, raw mode) |
| You only need the final result | You need to send data mid-execution | You need keystroke-level input |
pip install, go build, pytest | cat, wc, jq, database CLI, MCP server | vim, htop, ssh, gh auth login |
commands.run. Use stdio.start when you need to pipe
data into a running process. Use pty.create only when the command
requires a real terminal.
Architecture
stdio.start uses four REST endpoints plus one SSE stream:
| Operation | Method / route |
|---|---|
| Start process | POST /sandboxes/{id}/stdio — returns a cmd_id |
| Send stdin | POST /sandboxes/{id}/stdio/{cmd_id}/stdin |
| Close stdin | POST /sandboxes/{id}/stdio/{cmd_id}/stdin/close |
| Kill process | DELETE /sandboxes/{id}/stdio/{cmd_id} |
| Live output | GET /sandboxes/{id}/stdio/{cmd_id}/stream (SSE, base64-encoded frames) |
event: stdout and event: stderr frames with
base64-encoded data, plus a final event: exit frame with the exit code.
Quick start
- Python
- TypeScript
- Go
Multi-round interaction
Send multiple lines of input to a process that reads in a loop:- Python
- TypeScript
- Go
Environment variables and working directory
- Python
- TypeScript
- Go
Killing a process
- Python
- TypeScript
- Go
Next steps
- Python SDK: Stdio reference —
StdioProcess, iterator protocol, threading notes - TypeScript SDK: Stdio reference — TypeScript equivalent
- Go SDK: Stdio reference — Go equivalent
- Cookbook: interactive stdio — 6 runnable demos