7 min
How to slash sandbox memory usage by 75% using OverlayFS
See how a read-only erofs base with an OverlayFS tmpfs layer cut a Next.js sandbox from 4GB to 1GB, and where the writable layer still costs RAM.

Loading a full sandbox image into RAM keeps file access fast, but it caps how many sandboxes fit per host. Under Blaxel's original design, a base Next.js image needed 4GB, and a layered filesystem brought it down to 1GB. That 75% memory reduction is Blaxel's own measurement rather than an independent benchmark.
This guide is for engineering leaders whose agents execute code in production, and it explains the architecture behind that number. It also shows where the writable layer still costs RAM, and how to plan around it.
Key takeaways
- A read-only erofs base stays on disk, so each sandbox loads only the files it actually uses.
- Writes land in an in-memory tmpfs layer, which grows RAM use and is captured in the standby snapshot.
- Blaxel's Next.js measurement dropped from 4GB to 1GB, so plan host density around per-sandbox memory.
What goes wrong when you load everything into sandbox memory
The naive approach uses an initramfs to guarantee speed and minimize disk I/O. In this flow, the entire filesystem is loaded into memory at boot by unpacking a cpio archive into a tmpfs. This approach performs well once loaded, but it has a significant drawback.
The sandbox's memory footprint is dictated by the size of its base image and not its actual workload.
Say you need an environment with many pre-installed tools. You'd provision enough RAM for the entire OS and every tool. That's true even if your agent only ends up using curl. Each sandbox then uses more memory and starts slower. Multi-gigabyte images get copied into RAM before any work begins.
How using OverlayFS can save memory usage at boot
A way around this bloated memory usage is overlayfs, a dynamic on-demand file system.
At the bottom is a read-only base image. Think of it as a frozen, compressed snapshot of a complete operating system. It holds the binaries, libraries, and tools like Python. This image is stored on the hypervisor's disk in an efficient format called erofs (Enhanced Read-Only File System).
The sandbox kernel no longer unpacks a cpio archive at boot. It memory-maps this erofs image directly from disk. Say your agent runs python. The kernel reads only that program's data blocks from the read-only image, on demand.
This "lazy-loading" approach keeps the initial memory footprint small. Your sandbox only pays the memory cost for the components it actively uses.
So, what about writing files? On top of the read-only base, overlayfs adds a writable layer that lives entirely in the sandbox's RAM using tmpfs.
When your agent creates a log file or modifies a configuration, those changes are written to this in-memory layer. To your code, the filesystem looks like one normal, writable disk. Under the hood, overlayfs directs all reads to the erofs base and all writes to the fast tmpfs layer. That layer grows the memory footprint as the agent writes, and it's snapshotted along with the sandbox.
Where the writable layer still costs memory
The read-only base explains the savings, while the tmpfs layer explains where memory comes back.
OverlayFS writes through a process called copy-up. Copy-up copies a file from the read-only base into the writable upper layer before changing it.
| Trigger | Effect on the tmpfs upper layer |
|---|---|
| First write-open of a base file | The whole file is copied into RAM. Editing one line of a large lockfile copies the full file. |
| chmod or chown, when metacopy is enabled | Only metadata is copied, via metadata-only copy-up. Data waits until a write opens the file. |
| Creating a hard link | Triggers copy-up of the target. |
| Creating a symlink | No copy-up. |
Blaxel's sandbox docs state that tmpfs reserves about 50% of available sandbox memory when possible. In a 4GB sandbox, that's roughly 2GB for agent writes before the layer fills. The layer is also volatile. Blaxel's platform page notes data is wiped when a sandbox is destroyed. The same page says each sandbox runs in its own microVM with no shared kernel.
Classify what your agents write. Keep scratch files, build output, and logs in tmpfs, which Blaxel designs for session-local work. Send large or long-lived data to a Volume instead, so it doesn't inflate RAM or the standby snapshot.
Does OverlayFS share memory across sandboxes?
Most overlay2 guides cover disk usage; here the question is RAM. On a container host, Docker documents page cache sharing: containers reading the same file share one cache entry. Docker moved to overlayfs partly to avoid a hundred copies of glibc in the page cache.
But one study found about 0% sharing efficiency for three identical nginx containers on Azure. They used 9.88 MB total versus 3.29 MB each. Shared host pages also carry an isolation cost. Researchers showed that page-cache residency can leak a coarse trace of file activity between containers built from one image.
For AI-generated or untrusted code, the per-sandbox microVM boundary matters more than cross-tenant page sharing. Blaxel's savings come from on-demand loading inside each sandbox, not from sharing pages between sandboxes. EROFS page-cache sharing patches cut memory 16% to 49% when reading all files across two image versions. The feature landed in Linux 7.0 in February 2026, and it shares pages across EROFS mounts on a single kernel. Each microVM runs its own guest kernel, so host sizing still follows per-sandbox resident memory.
To test any platform's density claims, measure per-sandbox memory yourself:
- Drop host caches between runs.
- Record idle memory.
- Record memory after a real agent workload.
- Repeat several times.
What this means for you
This architecture cuts costs you'd otherwise pay in RAM, startup time, or storage:
- Lower memory usage: The base system isn't fully loaded into RAM, so each sandbox needs far less memory to run. You can run larger toolchains in smaller, cheaper sandbox sizes.
- Startup decoupled from image size: Boot time no longer scales with how many tools the image contains. Files load on demand, so a heavy image no longer has to enter RAM before the first command. That first read still comes from disk, which makes it slower than the reads that follow.
- Smaller standby snapshots: Because the base image stays on disk, the standby snapshot holds less data and costs less to store while idle.
Together, these let you reduce sandbox memory usage without trading away the startup speed coding agents depend on.
Build sandboxes around what agents actually use
A read-only erofs base with an in-memory OverlayFS layer keeps memory lean, as long as heavy writes go elsewhere.
For agents that execute code, compare a self-managed layout with platforms like Blaxel, where each sandbox gets its own microVM. Count standby snapshot storage in that comparison, since idle cost sits there once compute charges stop.
Blaxel keeps sandboxes in standby with no time limit, while higher quota tiers support unlimited persistence. Sandboxes resume in under 25ms with memory state intact. For data that must persist independently of a sandbox, use a Volume.
FAQs about OverlayFS memory usage
Does OverlayFS load the whole image into RAM?
No. The erofs base stays on the host disk, and the kernel reads each file only when the sandbox first uses it.
Where does the memory cost come back?
It comes back in the writable tmpfs layer, because opening a base file for writing copies the whole file into RAM. Blaxel reserves about 50% of sandbox memory for that layer when possible.
Do sandboxes share the saved RAM?
No. Each Blaxel sandbox runs in its own microVM, so the 4GB to 1GB drop comes from on-demand loading inside each sandbox.
What happens to files in the writable layer?
They live in RAM and travel with the standby snapshot until the sandbox is deleted. For anything that needs to outlast the sandbox, use a Volume.
Is the 25ms figure the time to create a sandbox?
No. That figure is the resume time from standby, and creating a brand-new sandbox is a separate step that takes longer.
Related articles

Engineering
Choose the right storage for your Blaxel agents
Blaxel agents have three storage options: the sandbox filesystem, volumes, and Agent Drive. Understand what each option does and when to use it.
12 min read

Engineering
Understand the lifecycle of a Blaxel sandbox
Learn how sandboxes are built, managed, billed, and cleaned up behind the scenes.
12 min read

Engineering
What if Lambda and EC2 had a baby? Anatomy of an agent runtime
See how Blaxel moved from Kubernetes and Cloud Run to Firecracker microVMs, with Carbon (Mark 3.1) now in private preview.
12 min read