You give a Firecracker microVM a fixed amount of memory at boot. Workloads do not use a fixed amount. The balloon device is how a host gets back memory a guest is not using, and how it can squeeze a guest that is using too much. It is also one of the few Firecracker features whose documentation comes with a security disclaimer in bold, which is a good reason to understand it before relying on it.
This post follows Firecracker's balloon documentation as of November 2026. It explains Firecracker itself; it does not describe how Sandscale or any other platform manages guest memory.
How a memory balloon works
A balloon is a virtio device with a driver inside the guest. The host sets a target size in MiB. The driver then:
- while the balloon is smaller than the target, allocates memory inside the guest and reports those pages to the host, which may then release them;
- while the balloon is larger than the target, frees memory back to the guest until it reaches the target.
Inflating the balloon takes memory away from the guest's processes; deflating gives it back. The host changes only the target size while the VM runs. The device's other options are fixed at configuration.
If the driver cannot allocate more, the docs say it logs Out of puff! Can't get %d pages, waits 0.2 seconds and tries again. That message in a guest's kernel log means the host is asking for more memory than the guest can give.
The options
-
deflate_on_oom: whentrue, if a guest process would push the guest into out-of-memory, the kernel takes pages from the balloon instead of invoking the OOM killer. It covers physical allocations for guest processes, not the kernel's own needs or allocations the guest's memory manager refuses outright. The docs walk through thevm.overcommit_memoryinteraction and do not recommend setting it to 1. -
stats_polling_interval_s: how often, in seconds, the guest driver updates balloon statistics; 0 disables them. -
free_page_reporting: the guest continuously reports memory ranges it is not using so the host can reclaim them. -
free_page_hinting(developer preview): a host-triggered way to reclaim free memory.
The part in bold
The balloon is paravirtualized: it only works if the driver in the guest cooperates. Firecracker's docs list what a well-behaved driver does: it does not change the target, it takes exactly as many pages as asked, it reports its size truthfully, it does not reuse inflated pages, and it gives correct statistics. Then they say Firecracker does not and cannot check any of that, because the guest is not trusted, and if the driver is compromised none of those statements are guaranteed.
Put plainly: the balloon is not a memory limit. A guest running hostile code with root can stop cooperating. The docs tell operators to make sure the host can cope with the Firecracker process using all the memory it was given at boot, even if the balloon was used to restrict it, and to monitor memory use. Their suggested responses to unexpected growth are to move the VM to a host with more memory via a snapshot, to kill the Firecracker process, or to enable swap at the cost of speed.
Two more consequences:
- Do not size a host on balloon targets. If you overcommit memory assuming balloons will hold guests down, one uncooperative guest can push the host into trouble.
- Treat balloon statistics as hints. They come from the guest driver. The docs say to view them as an indication, not a guarantee.
What the balloon cannot do, even with a broken driver, is leak memory between VMs. The docs say page frame numbers from the driver are checked to be inside the guest's own memory before Firecracker discards the ranges, so a guest cannot use the balloon to read or affect memory outside its own.
Where the real limit comes from
The hard memory bound for a Firecracker guest is the memory you configured at boot, enforced by KVM and the host. On the host side, the production guide points at the cgroup memory controller to bound the Firecracker process, and the jailer sets cgroups up. The balloon sits inside that bound and helps you use memory efficiently. It does not replace the bound.
For agent sandboxes, which run code nobody has reviewed, that distinction matters. Plan for each guest to use all of its configured memory. Use the balloon to get memory back from well-behaved guests that are done with it, never as the thing that keeps a hostile guest in check.
Balloons and snapshots
The docs' suggestion to move a VM to a bigger host via a snapshot is a reminder that snapshot and restore is also a memory management tool. If you build on both, test the combination with your guest kernel; microVM snapshot pitfalls covers other things that go wrong across a restore.
Where Sandscale fits
On Sandscale, each sandbox is a Firecracker microVM with the memory you choose within your plan's limits (memoryMb in the SDK), and you do not manage balloons. What you see when a sandbox runs out is in the run result: oomKilled is true when the command was killed for memory. Pausing a sandbox keeps its memory and disk; stopping it ends it. Sizing sandboxes covers picking a size.
Originally published on the Sandscale blog.