CAP_NET_ADMIN posture. Firecracker ships a companion binary, jailer, already downloaded into ~/sandkiln-tools/bin by install-firecracker.sh, that re-execs Firecracker inside a chroot, cgroup-v2-limited environment running under a dedicated unprivileged uid. It is opt-in and off by default. For what chroot, cgroups and setuid each do, and why the privileges are split this way, see The jailer and privilege model. For running genuinely untrusted workloads see Run untrusted code.
How it fits together
Jailer makes each VM’s chroot root mode 0700 and owned by that VM’s uid, which the unprivileged daemon cannot enter. Three pieces close the gap without giving the daemon any privilege:- A shared jail group (
jailer_gid, default600000). The daemon’s user is a member. Every jailed VM runs under its own uid but this one group. - The jail supervisor,
sandkiln-firecracker-supervisor, a small static binary that jailer runs in place of Firecracker. As the VM’s own uid it opens the chroot to the jail group, then runs Firecracker. It also kills Firecracker when the daemon closes a pipe to it, which is how the daemon stops a process it may not signal, and why a jailed VM never outlives a crashed daemon. - A group-owned tap pool, so a Firecracker running as another uid may attach to the daemon’s taps.
Host steps
- cgroups v2 must be enabled. It is the default on any current distribution. Check with
mount | grep cgroup2: acgroup2mount at/sys/fs/cgroupmeans it is ready. The jailer is invoked with--cgroup-version 2unconditionally. - Build and install the supervisor. It must be a static binary because it runs in an otherwise empty chroot:
scripts/setup.shdoes this. - Run the root steps once.
prepare-jailer.shcreates the jail group and adds the daemon’s user, makes the jailer setuid-root, makes the daemon’s user the owner of the parent cgroup directory (so it can remove each VM’s cgroup, which jailer never does), and creates the chroot base:The setuid bit does not survive a re-run ofinstall-firecracker.sh, which overwrites the binary; re-run the script after any jailer upgrade. The parent cgroup lives under/sys/fs/cgroup, which is recreated at boot, so run it again after a reboot (or from a boot-time unit). - Create the tap pool owned by the group instead of by the user:
A pool created for direct boots (owned by a user) is refused by a jailed Firecracker.
- Start the daemon from a session that has the group. Group membership applies to new login sessions: log in again, or run the daemon with
sg sandkiln-jail -c '...'. A systemd unit needsSupplementaryGroups=sandkiln-jail. - Enable it:
jailer_enabled = true, orSANDKILN_JAILER_ENABLED=true.
Startup self-check
With the jailer enabled the daemon runs the real jailer once at startup against a throwaway jail, then checks as its own user that it can use the jail, remove it and remove the cgroup. It refuses to start, with the reason, when:- the
jailerbinary is not setuid root; - the supervisor is missing, or is not a static binary;
- cgroup v2 is unusable, or the daemon cannot remove a VM’s cgroup (step 3);
- the daemon’s user is not in the jail group in the session that started it (step 5).
jailer_self_check = false skips it, only to diagnose. It also sweeps jails a previous daemon process left behind: a jailed VM cannot outlive its daemon, and jail ids restart at 1 with each process.
Settings
Everything else has a default (full list in Configuration):jailer_bin(~/sandkiln-tools/bin/jailer) andjailer_supervisor_bin(~/sandkiln-tools/bin/sandkiln-firecracker-supervisor). The supervisor’s file name must containfirecracker(jailer insists) and names the parent cgroup.jailer_gid(600000): the shared jail group.jailer_chroot_base_dir(~/sandkiln-tools/jail), created automatically at startup if missing. Keep it on the same filesystem asdrives_dirandrootfs_dir, so the rootfs and drive files hard-linked into each VM’s chroot link instantly instead of falling back to a real copy on every boot.jailer_uid_gid_base(600000) andjailer_pool_size(32). Together they reserve600000..600031as a dedicated uid range, handed out one distinct uid per concurrently running jailed VM and released on stop. Pick a base outside any real host account’s uid: the/etc/subuidconvention of staying at or above100000, and clear of anything/etc/passwdalready uses. Two jailed VMs ever sharing a uid would let one guest’s escaped process interfere with the other’s, which defeats the point. A uid whose process could not be killed is never reused until the daemon restarts.
POST /sandboxes request cannot opt out, deliberately, so a compromised or malicious API client cannot disable a security boundary the operator turned on.
Known limits
- Snapshotting a jailed sandbox is not supported:
POST /sandboxes/<id>/snapshotreturns400, and so does a plainDELETEthat would preserve the sandbox (409; use?keep=false). Resuming a snapshot always uses a direct spawn regardless of whether the jailer is enabled. A graceful daemon shutdown therefore destroys jailed sandboxes instead of snapshotting them; see Stopping. - A persistent drive that is writable must be on the same filesystem as
jailer_chroot_base_dir: it is hard-linked into the jail, and a copy would silently lose everything written to it, so a create with such a drive is refused with that explanation. Read-only drives and the rootfs may be copied. - Of the integration suite, the topics that need snapshots or warm pools cannot run with the jailer on, and their failures are all
snapshotting a jailed sandbox is not supported yet(or a pool that never warms):08-snapshots,11-fork,16-sandbox-history(snapshot part),18-pool,19-egress(snapshot part),20-snapshot-lineage,21-time-travel-restore,24-env-vars(snapshot part),25-long-running-commands(snapshot part),26-snapshot-disk-isolation,28-resume-fixup,29-snapshots-hold-no-taps, and the default-stop part of12-named-sandboxes. Every other topic passes, including06-drivesand10-jailer. - The jail group is shared. Two jailed sandboxes are separated by distinct uids and distinct chroots, not distinct groups, and the group-owned taps mean a Firecracker that is already compromised could open another sandbox’s tap. Only the daemon’s user should be in the group.
- A failure in the few milliseconds between jailer making the chroot root private and the supervisor opening it leaves a root-owned directory that only root can remove. The daemon reports its path.
kill -9 ends the jailed Firecrackers.