Quick Example
CommandResult includes exit_code, stdout, stderr, and, when returned by
the API, pid. A command that exits non-zero still returns a result; check
exit_code before treating the work as successful.
Choose An Execution Mode
| Need | SDK Call | Use When |
|---|---|---|
| Run and collect output after exit | sandbox.commands.run(...) | The command is short and bounded. |
| Stream output while running | sandbox.commands.run_streaming(...) or run(..., on_stdout=...) | Logs matter before the process exits. |
| Start long-running work | run(..., background=True) | You need a server or worker process to keep running. |
| Reconnect to a process | sandbox.commands.connect(pid) | A background process already exists and you need live output. |
| Manage a process | list(), get_logs(), send_stdin(), kill() | You need process inventory or cleanup. |
Shell Strings Vs Argv
Useshell=True for authored shell snippets, pipelines, redirects, and
environment expansion. Use args when you want exact argument boundaries
without shell parsing. The API rejects requests that combine shell=True with
non-empty args.
command, optional args, and shell.
Working Directory, Environment, And Timeout
cwd must be a valid sandbox path and cannot target Nullspace runtime-managed
paths under /workspace/.nullspace. envs are added only for that execution;
they do not persist after the command exits unless your command writes them to
disk.
Command Guides
Streaming
Stream stdout and stderr while a command is still running.
Run commands in background
Start long-running processes and manage them by PID.
Manage processes
List processes, fetch logs, send stdin, and terminate work.
CLI commands
Execute commands and stream processes from the Nullspace CLI.