Back to Microsandbox

Logs

docs/sandboxes/logs.mdx

0.5.42.7 KB
Original Source

Every sandbox records captured output to disk so you can read it later, even after the sandbox stops or crashes. Use msb logs <name> from the CLI or logs() from the SDK.

Read logs

bash
msb logs devbox
msb logs devbox --tail 100
msb logs devbox -f
msb logs devbox --grep ERROR
msb logs devbox --json | jq 'select(.s == "stderr")'

The default output includes user-program stdout, stderr, and PTY output. Add system diagnostics when you need runtime or kernel logs:

bash
msb logs devbox --source system
msb logs devbox --source all

Read from the SDK

<CodeGroup> ```rust Rust let handle = Sandbox::get("web").await?; let entries = handle.logs(&LogOptions::default())?; ```
typescript
const handle = await Sandbox.get("web");
const entries = await handle.logs();
python
handle = await Sandbox.get("web")
entries = await handle.logs()
go
handle, err := m.GetSandbox(ctx, "web")
entries, err := handle.Logs(ctx, m.LogOptions{})
</CodeGroup>

Use log options to filter at read time:

<CodeGroup> ```rust Rust let recent = handle.logs(&LogOptions { tail: Some(50), sources: vec![LogSource::Stdout, LogSource::Stderr], ..Default::default() })?; ```
typescript
const recent = await handle.logs({
    tail: 50,
    sources: ["stdout", "stderr"],
});
python
recent = await handle.logs(tail=50, sources=["stdout", "stderr"])
go
recent, err := handle.Logs(ctx, m.LogOptions{
    Tail: 50,
    Sources: []m.LogSource{m.LogSourceStdout, m.LogSourceStderr},
})
</CodeGroup>

Sources

SourceMeaning
stdoutCaptured from a non-interactive session's stdout
stderrCaptured from a non-interactive session's stderr
outputCaptured from a PTY session, where stdout and stderr are merged
systemLifecycle markers plus runtime and kernel diagnostics

Interactive sessions use a PTY, so stdout and stderr are merged before microsandbox receives them. Non-interactive exec calls keep the streams separate.

Diagnostic flows

Sandbox crashed

bash
msb ls
msb logs <name>
msb logs <name> --source system

Sandbox will not start

bash
msb create --name nope ...
msb logs nope --source system

Program produced no logs

msb create only boots a sandbox. Run something with msb run, msb exec, or an SDK exec call to produce user-program output.

On disk

Sandbox logs live under <sandbox-dir>/logs/:

FileContents
exec.logUser-program output as JSON Lines
runtime.logSandbox runtime diagnostics
kernel.logGuest kernel and agent console output
boot-error.jsonStructured startup failure details, when boot fails early