Sandbox
sandbox.exec()
Example
Example
exec_stream() instead. Raises ExecTimeoutError if timeout elapses and MicrosandboxError if the process can’t be spawned.
Parameters
cmdstr“python3”, “/usr/bin/node”).argslist[str] | ExecOptions | Noneargs list.cwdstr | Noneuserstr | NoneenvMapping[str, str] | Nonetimeoutfloat | NonestdinStdin | bytes | Nonebytes are sent inline; default is /dev/null.ttyboolrlimitslist[Rlimit] | NoneReturns
sandbox.shell()
Example
Example
/bin/sh). Shell syntax like pipes, redirects, and && chains works. Accepts the same keyword-only options as exec().
Parameters
scriptstr“ls -la /app && echo done”).cwd, user, env, timeout, stdin, tty, rlimitsReturns
Stream methods
sandbox.exec_stream()
Example
Example
ExecHandle that emits stdout, stderr, and exit events as they happen rather than buffering everything. Takes the same per-call options as exec(). Pass stdin=Stdin.pipe() to write to the process while it runs via take_stdin(). For TTY sessions, call resize(rows, cols) when the terminal dimensions change.
Parameters
cmdstrargslist[str] | ExecOptions | Nonecwd, user, env, timeout, stdin, tty, rlimitsReturns
sandbox.shell_stream()
Example
Example
shell(): runs script through the configured shell but returns an ExecHandle instead of buffering output.
Parameters
scriptstrcwd, user, env, timeout, stdin, tty, rlimitsReturns
Attach methods
sandbox.attach()
Example
Example
Ctrl+]) to disconnect without stopping the process. Returns the process exit code.
Parameters
cmdstrargslist[str] | Nonecwdstr | Noneuserstr | NoneenvMapping[str, str] | Nonedetach_keysstr | None“ctrl-]” or “ctrl-p,ctrl-q”).Returns
sandbox.attach_shell()
Example
Example
Returns
ExecHandle
Returned by exec_stream() · shell_stream()
A handle to a running streaming execution and its events. A configured streaming timeout is enforced by the SDK even when the caller is not reading output. At expiry, the SDK waits for process startup before sending SIGKILL. Waiting or collecting reportsExecTimeoutError after the guest confirms exit; cancelling a pending wait does not cancel the deadline. Raw event readers receive the actual exit event. If termination cannot be delivered, the SDK reports a separate error without claiming the process exited. The SDK connection must remain open for this client-owned deadline to run.
handle.id
str
Correlation ID for this execution
handle.take_stdin()
None after the first call, or when stdin wasn’t piped
Returns
ExecSink \| None
handle.recv()
None when the stream ends
Returns
ExecEvent \| None
handle.wait()
(code, success)
Returns
tuple[int, bool]
handle.collect()
Returns
ExecOutput
handle.signal()
handle.kill()
handle.resize()
uint16 dimensions
ExecSink
Returned by ExecHandle.take_stdin()
Writer for sending data to a running process’s stdin. Obtained fromExecHandle.take_stdin() when the execution was configured with stdin=Stdin.pipe().
sink.write()
sink.close()
Stdin
Used by exec() · shell() · exec_stream() · shell_stream()
Factory for process stdin configuration.Stdin.null()
/dev/null (default)
Stdin.pipe()
take_stdin() on the handle
Stdin.bytes()
StdinMode member.
Rlimit
Used by exec() · shell() · exec_stream() · shell_stream()
Frozen dataclass describing a POSIX resource limit. Construct one directly or via a factory, then pass a list as therlimits argument.
Rlimit.nofile()
Rlimit.cpu()
Rlimit.as_()
Rlimit.nproc()
Rlimit.fsize()
Rlimit.memlock()
Rlimit.stack()
Types
ExecOptions
Accepted by exec() · exec_stream()
Typed dictionary for passing arguments and per-call options together as the second positional argument. Use aStdin object to select a mode or raw bytes for inline data.
ExecOutput
Returned by exec() · shell() · ExecHandle.collect()
The result of a completed command execution: collected output plus exit status. All members are properties. In TTY mode,stdout_bytes contains the combined terminal output and stderr_bytes is empty because a PTY doesn’t preserve separate stdout and stderr streams.
ExecEvent
Emitted by ExecHandle
Native event object emitted byrecv() and by iterating an ExecHandle. Fields that don’t apply to a given event are None.
ExecEventType
Returned by ExecEvent.event_type
String enum (enum.StrEnum) identifying a streaming execution event.
ExitStatus
Used by ExecHandle.wait()
Frozen dataclass describing a process exit result.ExecHandle.wait() returns the same information as a (code, success) tuple.
StdinMode
Used internally by Stdin
String enum (enum.StrEnum) identifying how command stdin is connected.
RlimitResource
Used by Rlimit.resource
String enum (enum.StrEnum) naming a limitable POSIX resource.
Managed jobs
Run and reconnect to background commands. See Background jobs for lifecycle, retention, and runtime limits.sandbox.exec_detached()
exec(). Stdin defaults to a retained pipe; Stdin.null() closes it, and bytes supply at most 64 KiB followed by EOF.
Example
Example
sandbox.get_job()
SandboxHandle.
sandbox.list_jobs()
SandboxHandle.
Job
job.id
job.inspect()
job.wait()
job.signal()
job.kill()
job.eof()
job.logs()
since is inclusive and until exclusive, both in Unix milliseconds; from_cursor cannot be combined with since.
job.log_stream()
await stream.close() when finished.
job.follow_logs()
logs().