Skip to content

feat(host): save and resume the state of jailed Firecracker VMs - #439

Merged
kalaspuff merged 4 commits into
mainfrom
fctl/859-save-and-resume-state-of-jailed-firecrac
Nov 7, 2026
Merged

kalaspuff merged 4 commits into
mainfrom
fctl/859-save-and-resume-state-of-jailed-firecrac

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On a host that runs as root, Firecracker VMs run through the jailer (#434), and until now they stopped without saving their state (#431), so a message booted the sandbox again from its disk and Claude started over. Now a jailed VM saves and resumes as an unjailed one does:

  • Saving. Firecracker writes vmstate and memory at the root of its chroot, as the jail's user. The host takes each out to the sandbox's saved/ by the file it opened without following a link, after checking that it is a regular file of the jail's user's with no other name, so that the jail can't hand it a link to a host file or the disk it was lent. It then gives each to root, mode 0600.
  • Resuming. The host makes a new jail as a start does, but without a configuration file: hard links of the disks the VM booted with, at the same paths in the chroot, and of the saved state, lent to the jail's user (who must read it) and noted in jail.json, so that it is given back. It starts the jailer, loads the state (PUT /snapshot/load), and only then links the vsock's socket out, since Firecracker makes it as the state loads. The state's links in the chroot go once it has loaded.
  • Records. The host now keeps a jailed VM's configuration, with its own paths, in the sandbox's directory, where the jail can't change it. It needs the VM's memory size for the room check and for spotting a session that asks for another size (neither worked for jailed VMs), and the disks that a resume links in. Each saved state records whether it was saved in a jail, and resumes only where VMs run the same way.

CI's Firecracker job verifies it with KVM on x86_64. Its root step now also runs stopped_sandboxes_resume_where_they_were with the jailer, which it used to turn off. There a jailed VM saved its state in 3.3 s (60 MiB of memory on disk) and resumed in 78 ms with its programs running, as fast as an unjailed one, and Firecracker ran as a jail's user again after the resume. As root, boots_a_sandbox and the package-caches test now save and resume their jailed VMs too. A new root-only unit test, which CI's root step runs and I ran here as root, makes real jails for a start, a save and a resume against a stand-in jailer and Firecracker API. Other unit tests cover the checks on what the host takes out of a jail, and a state saved in or out of a jail being refused on the other side.

Worth confirming

  • Decision: a state saved in the jailer resumes only in one, and a state saved without it only without. Turning jailer on or off, or moving a host to root, lets the states kept before go: those sandboxes boot from their disks, with a line in the session's log saying why.
  • Decision: a VM that a v0.30.2 host started in a jail stops without saving its state the first time an updated host stops it, because the host has no record of its configuration. It boots from its disk then, and saves normally from that boot on.
  • Decision: the host scans a saved memory file for zero pages only as far as the VM's memory reaches, since a jailed Firecracker made the file and could make it much longer.

Fixes #437
Refs #345

fctl session


Note

Medium risk. It changes how root-run hosts stop and resume Firecracker VMs, moving files between a jail the VM controls and the host's own directories as root, so a flaw in those checks could let a jailed VM reach host files.

What it does. Jailed Firecracker VMs (hosts running as root) now save their state when they stop and resume from it, as unjailed VMs already did. The host takes the vmstate and memory files out of the jail's chroot with checks that they are plain files of the jail's user, and on resume it builds a new jail with hard links of the disks and saved state, loads the snapshot and links the vsock socket out. States record whether they were saved in a jail and resume only in the same mode, and the host now keeps a jailed VM's configuration in the sandbox directory.

Saved states and jailer mode. Turning jailer on or off, or moving a host to root, discards states saved before, and VMs a v0.30.2 host started in a jail stop without saving once, then boot from disk.

fctl review's first look at 8a005a1 · 6 files, +886 −213 · Review agent settings

fctl-sh Bot added 4 commits November 7, 2026 00:36
A jailed Firecracker writes its state at the root of its chroot, as the
jail's user: the host takes both files out to the sandbox's saved/,
each opened without following a link and checked to be a regular file
of that user's with no other name, and gives them to root. A resume
makes the jail as a start does, but without a configuration, with the
disks the VM booted with and the saved state lent to the jail's user,
loads it, and only then links the vsock's socket out.

The host keeps a jailed VM's configuration with its own paths in the
VM's directory, for its size and the disks a resume needs, and records
whether a state was saved in a jail, which it then resumes only in one.

Refs #437
A root-only unit test runs a jailed VM's save and resume against a
jailer and Firecracker's API standing in, in a real jail; another checks
that the host takes out of a jail only what Firecracker saved there.
CI's root step runs it, and stopped_sandboxes_resume_where_they_were,
which no longer turns the jailer off.

Refs #437
A jailed VM's state goes through its chroot: the host takes it out as
the files Firecracker made there, and lends it to a new jail to load.
A state resumes only as jailed as it was saved, and a VM that an earlier
fctl started in a jail stops without saving its state, since the host
has no record of its configuration.

Refs #437
@fctl-sh
fctl-sh Bot requested a review from kalaspuff as a code owner November 7, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Save and resume the state of jailed Firecracker VMs

1 participant