Copy-on-Write Memory and Agent Snapshot Efficiency

Snapshot-restore cuts idle agent costs by storing state on disk instead of running compute.

· 8 min read
Cover illustration for “Copy-on-Write Memory and Agent Snapshot Efficiency”
Kernel and OS Primitives for Agents · October 27, 2026 · 8 min read · 1,891 words

Snapshot-restore scheduling for idle AI agents replaces idle compute charges with snapshot storage charges, then restores execution state in under a second when work arrives. Copy-on-write memory makes this economical by preserving unchanged pages without duplicating them and storing changes at page granularity.

Why agent scheduling breaks without a memory-efficient snapshot mechanism

An agent scheduler must accommodate long waits between short periods of work. Agents wait for user input, tool responses, and scheduled triggers, and must keep their runtime state ready for the next turn. Waiting dominates the workload. If each waiting agent occupies a fully provisioned VM, per-user deployment accumulates an idle-capacity bill even when almost nothing is executing. The scheduler must therefore release compute while preserving the agent.

A warm pool of fully booted VMs preserves readiness, but someone pays for that capacity continuously, and sudden demand can exhaust it. Cold-booting a fresh VM for every turn avoids maintaining that pool, but kernel initialization, init, and agent startup add seconds to an interactive exchange. Neither approach fits long approval waits well. An agent paused for human approval may wait minutes or hours, with no useful computation to justify a running VM. Snapshot-restore changes what that wait costs by keeping compute-ready state on storage during the wait.

Diagram: Snapshot-Restore vs. Warm Pool vs. Cold Boot: The Cost Trade-off. Visualizes: Show three agent-readiness strategies side by side as a comparison across two dimensions: compute cost during idle and restore latency.

What copy-on-write memory actually does when a snapshot is taken

Moving an idle agent onto storage is economical only if preserving its memory does not require another complete copy at every pause. Copy-on-write, or CoW, marks existing memory pages as shared and copies a page only when a write requires the preserved version and the running version to diverge. The incremental snapshot therefore tracks changes since the previous snapshot. An agent that is mostly idle leaves a small delta.

During the snapshot phase, memory is marked copy-on-write, and CPU and device state are serialized to disk with the memory image. The VM can then continue running or remain paused. Restore follows a different path from a boot. The memory file is mapped with MAP_PRIVATE, and pages enter RAM on demand as execution touches them, rather than all being loaded before execution resumes. This lazy loading allows sub-second restore even for guests with several gigabytes of memory, and the saved CPU and device state lets them pick up where they left off.

How Firecracker applies CoW to make snapshot-restore practical for agent workloads

Firecracker applies this mechanism through a lifecycle that boots a microVM fully once and captures its running memory and device state as a template. Subsequent agent creation can restore that template. Cold boot becomes a template cost. For an agent that has already begun work, restoring its own later snapshot instead preserves the state accumulated since creation. These two uses serve different purposes, but both avoid rebuilding a running machine from startup.

Firecracker restores by mapping the snapshot file and loading CPU state, without running a kernel boot sequence. Its minimal VMM has no BIOS, PCI bus, or legacy device emulation, so little needs reinitialization during restore. Implementation choices still shape the resulting latency. The ForgeVM project, a Go-based Firecracker orchestrator, achieved 28ms snapshot restores using a custom agent binary as PID 1 inside each VM. That result places sub-50ms restoration within reach of an implementation, rather than treating it as a theoretical property of snapshots.

Vercel Sandbox reached general availability with untrusted AI agent workloads running inside Firecracker microVMs. That deployment puts the architecture in a production setting. On October 3, 2026, CEO Guillermo Rauch announced a KVM 0-day through the Sandbox bounty program. The event also exposes the other side of production maturity, namely that infrastructure running adversarial workloads needs continuing scrutiny of its isolation boundary.

VM forking: CoW applied to agent parallelism and branching

CoW enables a running VM’s memory and disk to be cloned into N children, each sharing the parent’s unchanged pages and diverging as it writes. Fork cost follows divergence. A ready execution state can thus be a branch point for parallel work without a separately provisioned machine for every child. This makes snapshots an agent design primitive as well as a scheduling tool.

For a coding agent, that branch point can precede several competing refactors. Each child begins with the same environment and runtime state, then develops its own attempt as its memory and filesystem change. Without CoW forking, the alternatives are to serialize the attempts or provision N full VMs from scratch, trading elapsed time against resource cost. Parallel hypotheses and controlled evaluations also use this pattern to try several paths from one captured state.

How do you stop paying for compute when your AI agents are idle?

A snapshot scheduler matches compute allocation to agent activity by capturing idle state, releasing the compute slot, and billing for the storage holding that state. When work arrives, it restores the agent in under a second and resumes compute billing during execution. The released slot can serve active work. Across a fleet of thousands of agents, this changes the allocation basis from total agent count to active concurrency. The economic benefit comes from not reserving execution capacity throughout every agent’s lifetime.

CoW makes repeated pauses practical because each pause need not add a full duplicate of the VM’s memory to storage. Memory is consistently the largest cost component at fleet scale, so excluding unchanged pages has a direct effect on idle-state cost. Storage still has a price. Its incremental footprint, however, follows how much agents changed between turns rather than simply multiplying every pause by the full memory allocation. That distinction is especially useful when the overwhelming majority of agents are waiting at any given moment.

The billing policy decides whether the buyer gets those savings. Wall-clock CPU and memory billing charges for time spent waiting, while active-CPU-only billing charges no CPU time when nothing is running. These are not interchangeable pricing models. A storage-only pause must also release the compute allocation, because stopping useful work inside a billed instance still leaves a bill. Platforms should therefore be compared on whether they release idle compute, what they charge to retain snapshots, how quickly they restore execution, and their advertised price for running CPU.

What persistent state actually survives a snapshot-restore cycle

Diagram: What a Snapshot Actually Preserves (and What It Doesn't). Visualizes: Visualize two columns contrasting what survives a VM snapshot-restore versus what does not.

A database-backed restart and a VM restore keep different parts of an agent’s state. Serverless functions, container restarts, and context-window injection can reconstruct an agent’s working context by feeding saved information into a fresh process. A snapshot instead preserves the execution state itself. In-memory variables and data structures return as part of that runtime, rather than as records that application code must interpret to rebuild it.

The saved environment includes installed packages and filesystem state, so a tool installed mid-task is still there after restore. A browser-using agent resumes its browser session rather than launching a fresh browser at the last recorded URL. Credentials can remain in memory or the filesystem. Likewise, an agent processing a large file can resume from its captured position instead of reconstructing progress from an external record.

A wait for human approval shows the difference clearly because it pauses an unfinished task, which may still be far from a clean application boundary. The captured state can include open file handles, authentication tokens, and partial computation while the scheduler releases compute for the wait. The agent resumes at the captured execution point. That is a stronger local-state guarantee than remembering the last instruction and starting again. It describes preservation of the VM’s state, however, rather than a promise that external services or credentials remain valid throughout the pause.

The MCP statelessness shift and what it means for where agent state must live

The MCP 2026 specification, version 2026-07-28, makes the protocol explicitly stateless by removing the initialize handshake and the Mcp-Session-Id header. It also eliminates the assumption of sticky routing between client and server. Protocol sessions no longer anchor application continuity. The release candidate was locked May 21, 2026, and the final specification was published July 28, 2026. Roots, sampling, and logging are deprecated with minimum 12-month windows before removal eligibility, with the timing of removal thereafter left open.

For agent deployment, the application must manage session identity and context continuity explicitly. A request can no longer depend on protocol-level stickiness to recover the agent’s context. State needs a home outside the transport. In a snapshot-based architecture, the VM provides that home for live runtime state, and the snapshot preserves it across sleep cycles. Restoring the agent consequently does not depend on recovering a session header or reaching the same protocol server instance.

The CLI and MCP workflow distinction remains useful within that architecture. CLI tool calls create a new process per invocation and suit development and debugging, while MCP servers suit production agent runtimes whose application state persists across calls. Persistence does not come from the protocol itself. MCP also has a token-cost trade-off, since connecting a standard GitHub MCP server can load a lot of context before useful work starts. Its standardized authentication layer also helps across a fleet by using a single authentication mechanism in place of credentials managed for each tool.

Isolation requirements for multi-tenant agent fleets running on snapshot infrastructure

One user’s agent must not read another user’s memory, filesystem, or credentials, and incorrectly implemented CoW sharing could expose another VM’s pages. Sharing requires an enforced isolation boundary. Firecracker gives each microVM its own kernel, memory space, and CoW storage layer, rather than placing tenants inside a shared kernel namespace. That architecture addresses a boundary that container-based isolation leaves shared, but it does not make the underlying hypervisor immune to vulnerabilities.

The Sandbox bounty event illustrates why that distinction is consequential. A hypervisor-level vulnerability can cross VM boundaries even when the intended architecture separates guest kernels and memory. Isolation therefore requires ongoing adversarial testing. Treating microVM deployment as a one-time security decision would confuse the presence of a boundary with proof that the boundary cannot fail. Snapshot infrastructure must preserve tenant separation through both execution and the storage mechanisms that make suspension economical.

Credential delivery needs a separate defense because a compromised agent can expose secrets that are legitimately present inside its VM. Proxy-based injection at the network layer is the stronger defense here because it keeps private keys out of the sandbox filesystem. The key is never there to steal. This approach differs from preserving credentials inside a snapshot, which maintains continuity but also retains those credentials within the guest’s state. The two mechanisms solve different problems, namely resuming authenticated work and limiting what a compromised guest can reveal.

Prompt injection can still get through MicroVM isolation. Malicious instructions in a file or tool response can still direct an agent to act within the permissions its sandbox allows. Isolation limits the resulting blast radius instead. Safe multi-tenant deployment therefore needs containment as one layer of defense alongside measures addressing malicious instructions. Economic isolation and security isolation must work together before cheap per-user VMs are a sound basis for a product.

For developers building agent-native products, the practical division of responsibility is that the infrastructure handles the snapshot lifecycle, CoW storage management, and sub-second restore. The developer deploys code to a live API endpoint without having to manage those scheduling steps. That division makes persistent per-user agents practical. Their runtime can remain available across long waits without reserving a running VM for every user, while the infrastructure remains responsible for protecting the state it preserves.

Sources

  1. Instantaneous save/restore of virtual machines with persistent memory
  2. Instantaneous save/restore of virtual machines with persistent memory

More in Kernel and OS Primitives for Agents