Lifecycle
- Create with an idle timeout (e.g., 10 minutes)
- Use — every API interaction (execute, upload, download, wake) resets the idle timer
- Auto-suspend — after the idle timeout, the VM’s full state is snapshotted to disk
- Wake — any API call to a suspended sandbox triggers automatic restoration
- Destroy — manual teardown cleans up all resources including snapshot files
Creating a persistent sandbox
- CLI
- API
--template(required) — Template name or ID--persistent— Enable persistent mode--idle-timeout— Duration of inactivity before auto-suspend (default:10m)--size— VM preset (default:shared-cpu-1x)--env KEY=VALUE— Environment variables (repeatable)--egress-mode— Outbound firewall mode:allow_allordeny_all--egress-allow-cidr CIDR— Allow outbound to this CIDR (repeatable; impliesdeny_all)--egress-deny-cidr CIDR— Explicitly deny outbound to this CIDR (repeatable)--egress-allow-port PORT— Restrict allowed CIDRs to this TCP port (repeatable)
Auto-suspend
A background idle detection loop runs every 10 seconds and checks thelast_activity_at timestamp against the configured idle_timeout_seconds. When a sandbox has been idle for longer than its timeout, it is automatically suspended.
What counts as activity
The idle timer is reset by any of these operations:- Executing a command (
execute) - Uploading a file (
upload) - Downloading a file (
download) - Listing a directory
- Waking the sandbox (
wake)
Read-only operations like
GET /v1/sandboxes/{id} (status check) do not reset the idle timer. This prevents monitoring from keeping sandboxes alive indefinitely.What happens during suspend
- The Firecracker VM is paused via the Firecracker API
- A full snapshot is created — both CPU/register state (
vmstate) and memory contents (mem) - Snapshot files are stored at
/var/lib/zwrm/snapshots/{machine_id}/ - Permissions are restricted to
0600(snapshot contains memory contents) - The Firecracker process is killed, freeing CPU and memory
- The TAP network device is removed
- The database record is updated: status →
suspended, snapshot path saved
RestoreConfig is preserved in the database, containing everything needed to reconstruct the VM:
- Kernel path and boot arguments
- Network configuration (MAC, guest IP, gateway IP, subnet mask)
- Image and overlay paths
- vCPU and memory settings
Waking a suspended sandbox
You can explicitly wake a sandbox:- CLI
- API
What happens during wake
- An atomic status transition (
suspended→restoring) prevents concurrent restore attempts - A new TAP device is created with the original network configuration
- The Firecracker VM is restored from the snapshot files
- The VM resumes execution from the exact point it was suspended
- Snapshot files are cleaned up after successful restore
- The database is updated with the new machine ID and IP
Restore typically completes in under 500 milliseconds. The VM resumes with all processes, open files, and in-memory state intact.