stream_logs(), which captures output from the command passed to Sandbox.run(). Output from exec() commands isn’t included. Use Process.stdout or Process.stderr for that.
stream_logs() returns a StreamReader that yields log lines. Iterate synchronously or asynchronously.
When you call
Sandbox.run() without a command, the sandbox’s default command doesn’t write to stdout or stderr, so stream_logs() returns no output. Pass a command that writes to stdout or stderr.Retrieve recent logs
Usetail_lines to fetch the most recent log lines without streaming the entire history. This is useful for quick inspection of a running sandbox.
Follow mode
Stream logs continuously, liketail -f. The iterator blocks until new data arrives.
Ctrl+C to stop when iterating in follow mode.
Filter by time
Passsince_time to retrieve only logs after a specific timestamp. This narrows output to a window of interest, such as logs since a deployment or incident.
Timestamps
Settimestamps=True to prefix each line with an ISO 8601 timestamp from the server. Server-side timestamps help correlate sandbox events with other systems.
Async iteration
If your application usesasyncio, iterate over the same StreamReader with async for to avoid blocking the event loop.
Retrieve logs from stopped sandboxes
Logs remain available after a sandbox stops, which lets you investigate failures or review output from completed work. Retrieve historical logs from sandboxes that completed, failed, or terminated:follow=False (the default).
See also
- Command execution: Running commands and streaming their output with
exec() - Sync vs async: Iteration patterns