Home / Guides

Engineering

How a VM sleeps in 3 seconds and wakes in 0.04

Your agent stops, the VM saves its memory to disk and stops costing money. When you come back, every process is still running. Here's how it works, with the bash we actually run.

Updated 2026-11-29 · 6 min read

Most agent sandboxes make you choose. Keep the VM running and pay for idle hours, or stop it and lose everything in memory: the dev server, the half-finished agent session, the shell you left open. Snapshots of the disk are common. Snapshots of the whole machine are rarer.

Every Yurt VM is a Firecracker microVM, and Firecracker can snapshot a running VM: CPU registers, devices, and all of guest RAM. We use that for sleep. On our test box today:

StepTimeWhat survives
yurt sleep~3 sRAM, CPU state, disk
yurt wake~0.04 sProcesses keep running where they stopped

Sleep: pause, snapshot, stop

Firecracker exposes an HTTP API on a Unix socket. Sleeping a VM is three calls and a systemctl stop:

api() { curl -fsS --unix-socket "$SOCK" -X "$1" "http://localhost$2" \
          -H 'Content-Type: application/json' -d "$3"; }

api PATCH /vm '{"state":"Paused"}'
api PUT /snapshot/create '{"snapshot_type":"Full",
  "snapshot_path":"'$D'/vmstate.new","mem_file_path":"'$D'/mem.new"}'
systemctl stop "yurtvm-$NAME"
mv "$D/vmstate.new" "$D/vmstate"; mv "$D/mem.new" "$D/mem"

Pausing first matters: the snapshot has to be consistent, so the vCPUs must be stopped while it is written. A Full snapshot writes all of guest memory to mem and the small device and CPU state to vmstate. Most of the 3 seconds is writing RAM to disk, so a bigger VM takes longer to fall asleep.

The bug we hit first

Notice the .new files. Our first version wrote the snapshot straight over the old mem file. That breaks the second sleep: a VM that was woken from a snapshot is still using its old memory file as backing memory. Overwriting a file that a running VM has mapped corrupts it. So we write to new files and swap them only after the process has stopped.

Wake: load the snapshot and resume

ip tuntap add "$TAP" mode tap 2>/dev/null || true   # gone after a host reboot
ip addr replace "10.200.$ID.1/24" dev "$TAP"
ip link set "$TAP" up

systemd-run --unit="yurtvm-$NAME" --collect firecracker --api-sock "$SOCK"
api PUT /snapshot/load '{"snapshot_path":"'$D'/vmstate",
  "mem_backend":{"backend_type":"File","backend_path":"'$D'/mem"},
  "resume_vm":true}'

Why 40 milliseconds and not 3 seconds? With the File memory backend, Firecracker doesn't read the whole memory file back. It maps it. Guest pages are loaded from disk the first time the guest touches them. The VM starts running right away and pulls in memory as it needs it.

The network has to look the same after wake: same tap device name, same host-side address. The snapshot remembers which device the VM was attached to, so we recreate the tap before loading. If the host rebooted while the VM slept, that is the only thing that was lost.

What it feels like

$ yurt ssh me
root@me:~# python crawl.py &
[1] 418
root@me:~# exit
$ yurt sleep me
me sleeping (3.0s)
$ yurt wake me
me awake (0.04s)
$ yurt ssh me
root@me:~# jobs -l
[1]+   418 Running    python crawl.py &

The process never knew. For an agent this means the Claude Code session, its working tree and the dev server it started are still there when the next prompt arrives.

Caveats, honestly

Questions

Does a Firecracker snapshot keep running processes?

Yes. A full snapshot saves guest memory, CPU registers and device state. After restore, processes continue from the instruction where they were paused.

Why is restoring a snapshot faster than taking one?

Taking a full snapshot writes all guest RAM to disk. Restoring with the File memory backend maps the memory file instead of reading it, so pages load only when the guest touches them.

Do network connections survive a snapshot?

Connections inside the VM survive. A remote server on the other end may have timed out while the VM slept, so clients should reconnect.

Sources

  1. Firecracker snapshot support, read 2026-11-29

Give your agent its own computer. Full root, its own IPv6, and it sleeps with its memory when idle. Plans from $20/month, paid back as VM time.

curl -fsSL https://getyurt.dev/install | sh

Keep reading