sb = Sandbox().create(). Its process manager runs commands inside the sandbox.
Python execution
SandboxProcessResponse: stdout, stderr, and result are strings, and result concatenates stdout and stderr. A nonzero exit code indicates an error in the executed code. Install imported dependencies in the sandbox’s Image before running it.
Pass blocking=False to run_code to return a SandboxProcess immediately:
Commands and shell expansion
exec(*args, cwd="/workspace", env=None, stdin=None) always returns a process handle. It has no blocking parameter. Arguments are literal; invoke sh -c for pipes, variables, or redirection:
Standard input
Supply a string, bytes, or an open binary file asstdin. Input is uploaded before execution, followed by EOF; this is not an interactive input stream.
Output and cancellation
stdout, stderr, and logs are stream properties on a process. They support iteration and read(). Stream reads consume output; choose separate streams or combined logs depending on what you need.
process.status() returns (exit_code, status). A negative exit code means it is still running. wait(timeout=30) limits how long the caller waits; it does not kill the process on timeout. Call process.kill() to cancel it.
Async interface
Use.aio on a created sandbox for async operations. Sandbox creation itself is synchronous; move it to a worker thread when using an event loop: