You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add docs/guides/logging.md covering stream_logs() and the
aviato logs CLI command. Add interactive_streaming_sandbox.py
example for log streaming.
Update execution.md, sync-vs-async.md, troubleshooting.md,
mkdocs.yml nav, and AGENTS.md files with new entries.
Copy file name to clipboardExpand all lines: AGENTS.md
+10-1Lines changed: 10 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,11 @@ with Sandbox.run("sleep", "infinity") as sb:
35
35
print(line, end="")
36
36
result = process.result() # Get final ProcessResult
37
37
38
+
# Streaming logs
39
+
with Sandbox.run("sleep", "infinity") as sb:
40
+
for line in sb.stream_logs(follow=True, tail_lines=100):
41
+
print(line, end="")
42
+
38
43
# Async context manager
39
44
asyncwith Sandbox.run("sleep", "infinity") as sb:
40
45
result =await sb.exec(["echo", "hello"])
@@ -46,6 +51,7 @@ Key methods:
46
51
-`wait()`: Block until RUNNING status, returns self for chaining
47
52
-`wait_until_complete(timeout=None, raise_on_termination=True)`: Wait until terminal state (COMPLETED, FAILED, TERMINATED), return `OperationRef[Sandbox]`. Call `.result()` to block or `await` in async contexts. Set `raise_on_termination=False` to handle externally-terminated sandboxes without raising `SandboxTerminatedError`.
48
53
-`exec(command, cwd=None, check=False, timeout_seconds=None, stdin=False)`: Execute command, return `Process`. Call `.result()` to block for `ProcessResult`. Iterate `process.stdout` before `.result()` for real-time streaming. Set `check=True` to raise `SandboxExecutionError` on non-zero returncode. Set `cwd` to an absolute path to run the command in a specific working directory (implemented via shell wrapping, requires /bin/sh in container). Set `stdin=True` to enable stdin streaming via `process.stdin`.
54
+
-`stream_logs(follow=False, tail_lines=None, since_time=None, timestamps=False)`: Stream logs from sandbox, return `StreamReader` directly. Iterate synchronously with `for line in reader` or asynchronously with `async for line in reader`. Set `follow=True` for continuous streaming (like `tail -f`). Set `timestamps=True` to prefix lines with ISO 8601 timestamps.
-`stop(snapshot_on_stop=False, graceful_shutdown_seconds=10.0, missing_ok=False)`: Stop sandbox and return `OperationRef[None]`. Raises `SandboxError` on failure. Set `snapshot_on_stop=True` to capture sandbox state before shutdown. Set `missing_ok=True` to suppress `SandboxNotFoundError`.
@@ -140,7 +146,7 @@ data = await ref
140
146
**Exec Types** (`_types.py`): Types for command execution, returned by `Sandbox.exec()`:
141
147
142
148
-`Process`: Handle for running process with `stdout`/`stderr` StreamReaders and optional `stdin` StreamWriter. Properties: `returncode` (exit code or None), `command` (list executed), `stdin` (StreamWriter when `stdin=True`, or None). Methods: `poll()`, `wait(timeout)`, `result(timeout)`, `cancel()`. Awaitable in async contexts.
143
-
-`StreamReader`: Dual sync/async iterable wrapping asyncio.Queue. Supports both `for line in reader` and `async for line in reader`.
149
+
-`StreamReader`: Dual sync/async iterable wrapping asyncio.Queue. Supports both `for line in reader` and `async for line in reader`. Exception instances in the queue are re-raised to the consumer (used by `stream_logs()` to propagate errors).
144
150
-`StreamWriter`: Writable stream for stdin. Methods: `write(data: bytes)`, `writeline(text: str)`, `close()`. All return `OperationRef[None]`. Property: `closed` (bool). Uses bounded queue (16 items, ~1MB with 64KB chunks) for backpressure.
145
151
-`ProcessResult`: Dataclass with `stdout`, `stderr`, `returncode`, `command`, plus raw byte variants (`stdout_bytes`, `stderr_bytes`).
146
152
@@ -298,12 +304,15 @@ Commands:
298
304
|---------|------|-------------|
299
305
|`aviato exec`|`cli/exec.py`| Execute a command in a sandbox (`--cwd`, `--timeout`) |
300
306
|`aviato list`|`cli/list.py`| List sandboxes with optional filters (`--status`, `--tag`, `--runway-id`, `--tower-id`) |
Container logs capture stdout and stderr from the sandbox's main process (PID 1). Commands run via `exec()` produce output on the exec stream, not container logs. To generate logs visible to `stream_logs()`, your sandbox command must write to stdout or stderr.
73
+
74
+
## See also
75
+
76
+
-[Command Execution](execution.md) — running commands with `exec()`
77
+
-[Sync vs Async](sync-vs-async.md) — iteration patterns
0 commit comments