Skip to main content
axed does not take snapshots. The platform does, usually without telling the guest: gVisor’s runsc checkpoint, Firecracker snapshots, or Agent Substrate’s suspend.

What survives

A memory snapshot captures the whole sandbox, so everything axed holds comes back:
  • every process, running or finished, with its id, name, labels and exit status,
  • every output log, with the same offsets,
  • every stdin offset,
  • the process table’s instance_id,
  • the listeners inside the sandbox.
What does not survive is every client connection. Streams such as Attach, Run, Watch and Files.Write break, and some platforms (Agent Substrate) cancel them before the snapshot is taken. A replace or create-only upload that had not committed leaves nothing behind. Clients must start watches again.
A broken Run stream kills its process unless you set detach, and a broken Exec call without a request_id kills its process too. Start long-running work with Start, or with Run and detach: true, if it must survive a snapshot.

Reconnect a client

1

Remember where you were

While attached, keep the process id and the offset one past the last output byte you received (Output.offset plus the length of data).
2

Check the instance

After reconnecting, call System.Info and compare its instance_id with the one you saw before. If it changed, the sandbox cold-booted. The old processes are gone and their ids return NOT_FOUND.
3

Reattach from your offset

You get exactly the bytes after the ones you saw, or a gap event if some were evicted in the meantime. See The output log.
4

Retry writes safely

Retry a start or an Exec with the same request_id and a stdin write with the same offset, and axed acknowledges work that already happened instead of repeating it. A process id you kept from before the snapshot can carry the instance_id you saw: if the sandbox cold-booted instead of restoring, the call fails with NOT_FOUND and reason INSTANCE_CHANGED. See Start processes and Terminals and input.

How axed detects a resume

Because platforms snapshot without calling into the guest, axed detects resumes itself. A background thread samples three clocks every second: CLOCK_MONOTONIC, CLOCK_BOOTTIME and CLOCK_REALTIME. Each pattern below counts as a resume: Each detected resume increments generation and records its time in resumed_at (the most recent 16). System.Info reports both; axectl info shows generation:
A scheduler stall longer than 5 seconds looks like a resume too. The cost is one extra generation and a timeout extended by the stall.

Timeouts count running time

A process timeout measures the time the sandbox ran: monotonic time minus the frozen time axed detected. When a timer fires, axed samples the clocks again before killing, so a timer woken by a VM resume does not kill on the spot. A process started with a 20 s timeout and suspended for an hour still gets 20 s of running time. See Signals, exits and limits. Time spent stopped by System.Freeze is not suspended time. The sandbox keeps running, so it counts toward timeouts.

Before a snapshot: Freeze

System.Freeze stops every process tree through its cgroup (cgroup.freeze), so nothing changes state while the platform captures memory. That includes background jobs a finished command left running, as an Agent Sandbox command does. It waits for every tree to change state, up to timeout (0 means 5 seconds), and returns changed and total, the number of trees that had tasks in them.
  • Freeze needs cgroups. Without them it fails with FAILED_PRECONDITION.
  • A changed lower than total means some trees did not finish changing state within the timeout.
  • Until the thaw, axed refuses to start processes, on every API, with FAILED_PRECONDITION (FROZEN), so nothing runs while the rest are stopped. Starts already under way finish first and are frozen with the rest. System.Health reports frozen.
  • The frozen state is part of the snapshot. Thaw after you restore, with Freeze or with thaw in Configure, or the processes stay stopped and starts stay refused.
Freezing is optional. A memory snapshot is consistent without it; Freeze gives you a quiet point, for example to snapshot the disk at the same moment.

After a restore: Configure

System.Configure hands axed state that only the host knows. Call it after every restore on platforms whose clocks do not reveal the resume. The response carries clock_correction (positive when the clock moved forward), the new generation, entropy_added, which says whether the kernel took the entropy, and thawed, the trees thaw thawed. axectl resumed sends the local wall time, 64 bytes of fresh entropy, and resumed: true:
axed checks the whole request first, then steps the wall clock, then adds entropy, then records the resume, and thaws last. A request that fails changes nothing that comes after the failure, and in particular does not count as a resume, so retrying it never inflates the generation. A clock step without CAP_SYS_TIME fails with PERMISSION_DENIED: setting the clock needs CAP_SYS_TIME. Entropy is best effort: without CAP_SYS_ADMIN it is skipped, entropy_added is false and axectl resumed prints entropy not added. The default image runs axed without either capability, so make sure the clock is within 50 ms or grant CAP_SYS_TIME.
axectl resumed uses the clock of the machine where axectl runs, so run it on the host or wherever the time is right.

Platform notes

gVisor’s clocks reveal the suspend on their own. Boot time includes it and monotonic time does not, so detection is automatic and timers are unaffected. gVisor offers no delegated cgroup, so Freeze is not available. After a checkpoint and restore, a detached process keeps running, replay from offset 0 is intact, generation becomes 1 with a gap about as long as the suspension, and a timeout fires after its full running time. See gVisor.
Firecracker freezes the guest’s clocks across a snapshot, so timeouts stay right without help, but the guest’s wall clock falls behind and nothing in the clocks reveals the resume. Call System.Configure (axectl resumed) after every restore: it steps the clock, adds entropy and records the resume. Clients reconnect through the surviving vsock listener. axed manages the guest’s cgroup v2 hierarchy there, so Freeze is available. See Firecracker.
Some platforms, Agent Substrate among them, restore from the persisted disk instead of memory when a memory snapshot is not available. That is a cold boot. axed starts fresh with a new instance_id and generation 0, and process ids from before return NOT_FOUND. Files on the persisted disk remain. Compare instance_id on every reconnect to tell the two cases apart. See Agent Substrate.
A platform that sends SIGTERM before suspending would normally make axed shut down. Start axed with --on-sigterm=stay to keep it running instead; System.Health then reports eviction_pending: true, and axectl info shows pending on its eviction line. SIGINT always shuts down.