onStdout / on_stdout and onStderr / on_stderr callbacks. Output arrives as the command produces it, one line at a time, or in chunks when it comes fast.
Even while streaming, the returned
result still holds the complete stdout and stderr.AsyncSandbox takes the same callbacks with an awaitable run(). See the Sandbox reference.Command timeout
timeoutMs / timeout_seconds is a wall-clock limit on the whole command. Output does not reset it. A command that keeps printing output still stops at the limit, and run() returns exit code 124. If you leave the timeout off, the limit is 30 seconds, so set a timeout that is longer than your longest expected run. See Timeouts for the defaults.
If the connection drops
If the stream ends before thefinished event (a network hiccup, say), run() throws SandboxError, and the sandbox then stops the command. A run() without callbacks is different: if the client goes away, the command keeps running until it exits or reaches its timeout. Either way, nothing reattaches to command output. Sandbox.connect(id) gets you the sandbox back to run new commands, not the old stream.
For a job that has to outlive the connection, start it in the background with its output in a file, then read the file later. run() returns as soon as the job starts, and the job isn’t bound by the command timeout: