Firecracker snapshot and restore: API, choices, timings and pitfalls
Last updated
A snapshot takes seconds, a restore milliseconds
Snapshot
Restore
Early resume
A Firecracker snapshot freezes a running microVM into two files, guest memory and device/vCPU state, so that a new Firecracker process can resume it exactly where it stopped. The API is four calls. The hard part is around them: file sizes, when they reach the disk, the guest clock, and what happens if you restore the same state twice.
Every API call here follows the Firecracker v1.17.0 documentation (released 2026-09-10). The timings come from the host we ran in Paris at the time, retired on 2026-11-10 ("our host" below): an Intel Xeon E3-1230 V2 (Ivy Bridge), 31 GiB of RAM, RAID1 SATA SSDs, Ubuntu 24.04 with kernel 6.8, Firecracker v1.17.0, guests with 2 vCPUs and 4 GiB of RAM, measured on 2026-10-30 and 2026-10-31. flockvm's VMs now run on another server, in France. Your disk will change the numbers, not the trade-offs.
What does a Firecracker snapshot contain?
Two files that Firecracker writes, plus the disks, which it does not:
| File | Holds | Size on our host (4 GiB guest) |
|---|---|---|
microVM state (snapshot_path) |
KVM and vCPU state, emulated devices, MMDS configuration | 18-24 KB |
guest memory (mem_file_path) |
every page of guest RAM | 4.0 GiB, written in full, not sparse |
| disk files | your root filesystem and other drives | unchanged; "managed by the users" |
Not in the snapshot, per the docs: the logger and metrics configuration, the MMDS data store (its configuration is kept), the vsock backend and serial emulation. The disk is the bigger trap: Firecracker fsyncs the block devices at snapshot time but does not copy them. Once the disk changes, the memory image no longer matches it, so we treat every snapshot as single use.
The state file carries a 64-bit CRC, checked before loading; nothing protects the memory file. Snapshot files are trusted by design: authenticate and encrypt them yourself if they cross machines.
How big a snapshot is
- microVM state file. KVM and vCPU state, emulated devices, MMDS configuration.
- 18-24 KB
- guest memory file. Every page of guest RAM, written in full, not sparse: as big as the RAM you gave the VM, not the RAM it uses.
- 4.0 GiB
- the memory file of an idle VM, once thinned. fallocate --dig-holes removes the zero pages, in about 16 s; the restore still works.
- 177 MiB
- thinned, for a VM holding 1 GiB of random data. Used RAM stays in the file: --dig-holes only removes pages that are all zeros.
- 1.2 GiB
How do you take and restore a snapshot, step by step?
Pause, create, stop the process, then load into a fresh process and resume. These are the requests from our host notes, sent over the API socket (paths are inside the jailer's chroot; our daemon now sends sync_snapshot_files: false, see below):
# 1. Freeze the vCPUs (9-10 ms on our host)
PATCH /vm {"state":"Paused"}
# 2. Write the two snapshot files
PUT /snapshot/create {"snapshot_type":"Full","snapshot_path":"/vmstate","mem_file_path":"/mem","sync_snapshot_files":true}
# 3. Kill the Firecracker process; keep the TAP device and the disk
# 4. New Firecracker process (through the jailer), then, before any other configuration:
PUT /logger {"log_path":"/firecracker.log","level":"Info","show_level":true}
PUT /snapshot/load {"snapshot_path":"/vmstate","mem_backend":{"backend_type":"File","backend_path":"/mem"},"resume_vm":true,"clock_realtime":true}
The rules that matter, all from the official docs:
PATCH /vm,PUT /snapshot/createand resuming are only allowed after boot.PUT /snapshot/loadis only allowed before the VM is configured; the logger and metrics are the only things you may set first.- If the target files exist,
snapshot/createtruncates and overwrites them. - The loaded VM stays
Pausedunless you pass"resume_vm": true(or sendPATCH /vm {"state":"Resumed"}afterwards). - The new process needs the same host resources under the same paths: disk files at the same path, TAP devices with the same names, the vsock socket with the same name.
network_overrides(added in 1.12.0) andvsock_override(1.16.0) insnapshot/loadlet you change the TAP name and the vsock socket path. - If the load fails, Firecracker exits. Keep a cold boot from the disk as the fallback.
mem_file_pathinsnapshot/loadstill works but is deprecated: usemem_backend.
Killing the process is optional: PATCH /vm {"state":"Resumed"} continues the same VM after a snapshot. We kill it to free the host's RAM.
Full or Diff snapshot: which one should you use?
| Full | Diff | |
|---|---|---|
| Memory file | every page of guest RAM | pages dirtied since the last snapshot (or boot), as a sparse file |
| Resumable alone | yes | generally no: merge it onto a base with snapshot-editor edit-memory rebase first (exception: the first Diff of a VM that was booted, not restored) |
| Needs | nothing | track_dirty_pages: true in /machine-config or /snapshot/load for exact tracking; otherwise Firecracker uses mincore(2), which only works with swap off |
| Cost while running | none | KVM dirty-page logging costs CPU and "negates most of the benefits" of huge pages |
| Status in v1.17.0 | generally available since 1.13.0 | developer preview |
| Use it for | pause and resume, one-off snapshots | frequent checkpoints of a large VM that changes little |
Merge layers in the order they were taken, and use the state file from the same call as the last layer merged. track_dirty_pages is not saved in the snapshot: set it again on every snapshot/load.
We use Full only: our VMs pause once per idle period, and a Full file can be thinned afterwards (below). Diff pays off when you checkpoint a big VM often and little of its RAM changes.
File or Uffd memory backend?
Firecracker does not read the memory file at load time. With File it maps it MAP_PRIVATE: pages load when the guest touches them, writes go to copy-on-write anonymous memory. Loading is fast, and the file must stay in place for the life of the VM.
File |
Uffd |
|
|---|---|---|
backend_path |
the memory file | a Unix socket where your page fault handler listens |
| Who serves page faults | the host kernel | your own process, through userfaultfd (UFFDIO_COPY) |
| Extra code | none | a handler you write and monitor (an example ships in the repo) |
2M hugetlbfs pages (huge_pages: "2M") |
rejected | supported |
| Failure mode | none of its own | if the handler dies, Firecracker hangs on the next fault, "forever" |
| Host setup on kernel 6.1+ | none | access to /dev/userfaultfd (the jailer exposes it in the jail) |
| Pick it when | the snapshot sits on a local disk | you prefetch pages, stream memory from the network, or need hugetlbfs |
On our host, LoadSnapshot with File takes 5-21 ms and sshd answers 45-74 ms after the load request, so Uffd has little to win for us. The cost of lazy loading shows up later, as slow first touches when the file has left the page cache.
How fast is snapshot and restore?
Our measurements, 2 vCPUs and 4 GiB of guest RAM, Firecracker v1.17.0, no CPU template:
| Step | sync_snapshot_files: true |
sync_snapshot_files: false |
|---|---|---|
PATCH /vm Paused |
9-10 ms | 9-10 ms |
snapshot/create Full |
17.7-22.5 s | 2.0-7.2 s, depending on the host's writeback backlog |
| kill, move files, clean up | about 0.6 s | about 0.6 s |
| new process until the API answers | 35 ms | 35 ms |
snapshot/load with resume_vm |
15-21 ms | 16-20 ms |
| load request → guest sshd banner | 45-64 ms | 48-74 ms |
Source: flockvm host/README.md, 2026-10-30. End to end through our host daemon (host/flockd/README.md, 2026-10-31): a pause takes 2.6-3.3 s on a quiet host, 7.5-17 s while the host writes other data back; a resume takes 0.30-0.43 s to running with sshd answering, 0.67-0.82 s to an SSH login from a Mac in France.
Snapshot creation is bounded by the disk, not by Firecracker. With fsync, writing 4 GiB took 17.7-22.5 s, which is 4,096 MiB ÷ 22.5 s ≈ 182 MiB/s to 4,096 MiB ÷ 17.7 s ≈ 231 MiB/s on these SATA SSDs. A full snapshot also faults every guest page in, so the file is as big as the RAM you gave the VM, not the RAM it uses.
Restore is cheap because no memory is copied. After resume, a process started before the pause has the same PID, 1 GiB in tmpfs matches its md5, boot_id is unchanged, and an outside SSH session kept running. The docs are more careful: packet loss is expected and connections are "not guaranteed" to survive.
Should sync_snapshot_files be true or false?
sync_snapshot_files arrived in Firecracker 1.17.0 and defaults to true: Firecracker fsyncs both files before the request returns. With false it returns as soon as the data is in the host page cache; "same-host reads still see the full contents" and only durability across a host crash is lost. Block device files are fsynced either way.
We run with false, which turned up two problems.
The page cache is charged to the VM's cgroup. Under a memory.max limit, writing a 4 GiB memory file pushes the process into reclaim. Our daemon lifts memory.max before the pause.
Finalizing the snapshot right after the pause slows down an early resume. A memory file is 4 GiB even when the guest uses little of it. fallocate --dig-holes removes the zero pages: 4.0 GiB became 177 MiB for an idle VM, and 1.2 GiB for a VM holding 1 GiB of random data in tmpfs, in about 16 s; the restore still works. Our first version dug the holes and then fsynced right after each pause. Measured on 2026-10-31 (commit b2f4b3a, host/flockd/README.md):
| Resume a few seconds after the pause | Resume time |
|---|---|
while --dig-holes runs |
1.2-3.6 s (7 runs); LoadSnapshot itself 5-63 ms, then sshd 0.6-3.2 s later |
while the fsync runs (fsync first) |
3.2-12.3 s (4 runs) |
| neither: the kernel writes the file back on its own | 0.73-0.94 s, idle or busy VM; 0.32 s when resumed 30 s after the pause |
| after the snapshot is finalized | 0.30-0.50 s |
Digging holes evicts pages from the page cache while keeping the disk busy, so the guest faults them back from a busy disk. The fsync hurt for a reason outside Firecracker: our daemon's SQLite commit waited behind gigabytes of writeback (ext4, data=ordered). The fix: finalize (holes, then fsync) only once the VM has stayed paused for 2 minutes; a resume, stop or delete cancels the wait.
The cost: a host crash in the ~2.5 minutes after a pause loses the memory state. The disk survives and the VM boots cold. If that is not acceptable, keep true and its 18-23 s snapshot.
Which snapshot, which backend, which sync
What is your case?
Pause and resume, one-off snapshots
Full
Every page of guest RAM, resumable alone. We use Full only: our VMs pause once per idle period, and a Full file can be thinned afterwards.
Frequent checkpoints of a large VM that changes little
Diff
Only the pages dirtied since the last snapshot, as a sparse file. Developer preview in v1.17.0, and generally not resumable alone: merge it onto a base first.
The snapshot sits on a local disk
File
The host kernel serves page faults, with no extra code. Loading is fast, and the file must stay in place for the life of the VM.
You prefetch pages, stream memory from the network or need hugetlbfs
Uffd
Your own process serves page faults, through userfaultfd. If the handler dies, Firecracker hangs on the next fault, "forever".
Losing the memory state in a host crash is not acceptable
sync_
The default: Firecracker fsyncs both files before the request returns. On our host that is an 18-23 s snapshot.
The VM may boot cold after a host crash
sync_
It returns as soon as the data is in the host page cache; only durability across a host crash is lost. Finalize only once the VM has stayed paused for 2 minutes.
Why is the guest clock wrong after a restore?
The docs say a restored VM resumes with its wall clock "continuing from the moment of the snapshot creation". On x86_64 with the kvm-clock clock source and a host kernel 5.16 or later, "clock_realtime": true in snapshot/load advances the clock at restore time. It is opt-in since Firecracker 1.16.0, which fixed the monotonic clock jumping by the paused time by default (CHANGELOG #5809). The docs warn that the guest sees the clock jump suddenly.
What we found: our guests used the tsc clock source, on which clock_realtime has no effect. After each restore the clock lagged by the paused time until systemd-timesyncd fixed it about 18 s later. Booting with clocksource=kvm-clock plus clock_realtime: true put it within ±0.01 s of the host at resume; timesyncd stays as a safety net.
What breaks when you restore one snapshot more than once?
Restoring one snapshot into several VMs is what people call forking a VM. The docs: "we consider resuming execution from the same state more than once insecure", because whatever the guest assumed unique is duplicated. Snapshot A, terminate it, load once in B: secure. Resume A and load in B: both insecure. What gets duplicated:
- Kernel entropy. Firecracker always enables the VMGenID device. Guests on Linux 5.18 or later reseed their kernel random number generator when it changes at restore. The docs still recommend the full reseed (
RNDADDENTROPYthenRNDRESEEDCRNG) to avoid a race, avirtio-rngdevice, and deleting/var/lib/systemd/random-seed. - Everything above the kernel. Cached random numbers, identifiers and tokens "will still be replicated". VMClock's
vm_generation_counterlets userspace notice a restore; it needs guest kernel patches merged in Linux 7.0. - Network identity. Every copy comes back with the same TAP name, MAC and IP. The docs' example puts each clone in its own network namespace (jailer
--netns) and rewrites addresses with iptables NAT;network_overrideshandles the TAP name. - vsock. The device is reset at
snapshot/create; on resume open vsock connections are closed, listening sockets survive. Clients must reconnect. boot_idstays the same; bind-mount another file over it if that matters.
flockvm does not fork VMs today: each snapshot is restored once, into the same VM, the docs' secure case. How flockvm's pause and resume use these snapshots is in How flockvm works. Forking is what flockvm is building next, and this list is its checklist. E2B and Daytona already fork with memory, and so does Morph Cloud, which calls it branching; see flockvm vs E2B, flockvm vs Morph Cloud and E2B alternatives.
Can you restore on another host or another Firecracker version?
The docs require a software and hardware configuration identical to the one the snapshot was taken on.
- Firecracker version. Each binary supports one snapshot format version, separate from its own (
firecracker --snapshot-versionprints it). The bitcode encoding allows no backwards-compatible change, so any state change bumpsMAJOR. In practice it moves often: 9.0.0 in v1.15.1, 10.0.0 in v1.16.0, 11.0.0 in the v1.16.2 patch release, 12.0.0 in v1.17.0 (SNAPSHOT_VERSIONinsrc/vmm/src/persist.rs). Treat every Firecracker upgrade as a snapshot break, or upgrade with no paused VM. - Host kernel. Same kernel is fine. Across kernels it "is considered unstable"; the docs list one known-good case on AWS metal instances (5.10 to 6.1, same instance type, one direction only).
- CPU. Another CPU model needs a CPU template common to both hosts; without one on x86_64,
MSR_IA32_TSX_CTRLwrites are lost. Our Ivy Bridge restores fine with no template on the same host; the static templates (T2, T2S, C3, T2CL) target Skylake and later, so moving would need the same CPU or a custom template fromcpu-template-helper. - arm64. No restore between GICv2 and GICv3 hosts.
- cgroups v1. The docs report high restore latency and "strongly recommend" cgroups v2.
What other pitfalls show up in practice?
- Never write to a loaded memory file. It backs guest RAM and modifying it "corrupts the guest memory". Since
snapshot/createoverwrites existing files, the next snapshot to the same inode corrupts the running VM: always write a new file. Unlinking the old one is safe. - Plan disk for RAM-sized files. 7 paused 4 GiB VMs need 7 × 4 GiB = 28 GiB before thinning. The docs say integrators "must" enforce quotas if users trigger snapshots; our daemon refuses a pause when free disk is below the memory size plus a reserve.
- Do not snapshot during early boot. VMGenID injects an interrupt at restore; if the guest kernel has not finished booting, it may not handle it and can crash. Take snapshots after boot.
- The filesystem stalls after a big write. After a multi-GiB snapshot, a new process sometimes took seconds to create its API socket (we wait up to 10 s), and a resume took up to 1.3 s (ext4 journal stalls).
- Used RAM stays in the file.
--dig-holesonly removes pages that are all zeros, and there is no balloon device on our VMs to hand memory back, so a VM that once filled its RAM keeps a large memory file.
Where flockvm uses this today
flockvm gives each coding agent its own Firecracker microVM; pause and resume are the sequence above (Full, sync_snapshot_files: false, File, kvm-clock with clock_realtime, deferred finalize). Sign-ups are open (Google, GitHub or an email link) with a 7-day free trial, card required and nothing charged for 7 days, and it runs on one host in France (OVHcloud), up to 15 small VMs at a time (see EU data residency), billed per second. No fork, secrets proxy or region outside France yet.
Choosing rather than building? Firecracker as a sandbox covers what you build around Firecracker, and the managed options, running Claude Code agents in parallel goes from worktrees to one VM per agent, and coding agent swarms covers swarms of 10 to 20 agents, the next step flockvm is building. For a managed service built on these snapshots, flockvm vs CodeSandbox SDK compares one that forks and resumes Firecracker VMs from memory.
Run your agents in their own microVMs
flockvm gives each coding agent a Firecracker microVM that pauses with its memory and resumes, billed per second. France is live, and you can start with a 7-day free trial.
Start your 7-day free trialCard required. Nothing charged for 7 days.