Sandbox.builder(...).create() boots a microVM, starts the guest agent inside it, and establishes a communication channel back to the host.
Understanding the lifecycle is useful once you start managing long-running sandboxes, graceful shutdown, or resilient agent workflows.
States
Create a sandbox
Creating a sandbox boots the microVM, mounts the filesystem, initializes the guest agent, and waits until it’s ready to accept commands. Names must be non-empty and no longer than 128 UTF-8 bytes.Stop and restart
Stopping gracefully terminates guest processes and shuts down the VM. The sandbox moves toStopped and can be restarted later with all its configuration preserved.
msb restart follows the same lifecycle semantics as msb stop followed by msb start. If the sandbox is already stopped or crashed, it starts it directly.
Configuration
Usemsb modify, or the SDK modify() methods, to change an existing sandbox without recreating it. Some changes apply live, some affect future execs only, and some need a restart or the next start.
Ping and touch
Useping to check that a running sandbox’s guest agent is reachable, and touch to intentionally refresh its idle timer. Ping is a health check only: it does not count as sandbox activity and will not keep an idle sandbox alive by itself. Touch is the explicit keepalive.
Kill immediately
If a sandbox is unresponsive (e.g., stuck in a tight loop or a panic), force-kill it. The sandbox is terminated immediately with no graceful shutdown. On cloud, use a graceful stop.Detach
Keeps a sandbox running after the parent process exits. It becomes a background process that you can reconnect to later withSandbox::get("worker").
Request drain
Trigger a graceful shutdown that lets existing commands finish but rejects new ones. The sandbox moves toDraining and transitions to Stopped when all in-flight commands complete. This is useful for zero-downtime rotation of worker sandboxes.
Wait until stopped
Block until the sandbox is observed in a terminal non-running state, without triggering a stop or kill request.Remove
Delete a stopped sandbox. Every local SDK entry point andmsb rm uses the same deletion scope.
Removing a sandbox does not undo writes made to a named volume, bind mount, or user-supplied disk image. On cloud, removal deletes the remote sandbox resource; the local disk details above do not apply.
List and inspect
Runtime process architecture
At runtime, your application talks to a host-side sandbox process, and that process relays requests to the guest agent inside the VM. The sandbox process also handles:- Graceful stop and drain signals
- Cleanup when the sandbox exits
- Idle detection and maximum lifetime enforcement
Logs and diagnostics
Usemsb logs or the SDK logs() method to read captured output from running, stopped, or crashed sandboxes. For source semantics, boot errors, and diagnostic flows, see Logs.