Serverless Functions vs Persistent Micro-VMs for Stateful Agent Workloads

Agents need persistent state; serverless destroys it between every invocation.

· 11 min read
Cover illustration for “Serverless Functions vs Persistent Micro-VMs for Stateful Agent Workloads”
Sandbox & Runtime · October 6, 2026 · 11 min read · 2,442 words

Serverless functions and stateful AI agents rest on opposite bets about what an execution environment owes the workload. Serverless promises that nothing survives past the end of an invocation. A stateful agent only works because something does.

Serverless and stateful agents encode opposite assumptions about state

The serverless contract is simple: compute gets allocated on demand, code runs, the environment gets torn down. The platform treats the disappearance of state as a feature, a guarantee that lets it pack workloads tightly and bill by the millisecond. Nobody designing AWS Lambda set out to lose your data. They set out to make sure nothing lingers that could complicate scheduling, security, or cost.

An agent's contract runs the other way. An agent works across a sequence of steps: it parses an output, installs a dependency, edits a file, calls a tool, comes back to check the result against something it did three steps earlier. Every one of those actions assumes the step before it left something behind on disk, in memory, in an open session. Without that assumption, the agent's actions become a series of unconnected guesses.

This isn't a tuning problem you can solve by adjusting timeouts or adding a cache layer. Serverless and agents sit at opposite ends of a design decision about what the environment is supposed to preserve, and no amount of configuration closes that gap on its own. The usual framing, serverless against containers, muddies this further, because containers look like they split the difference: they hold onto session state the way an agent needs, but every container on a node still shares the same Linux kernel. Serverless, meanwhile, gets its isolation from Firecracker's hardware virtualization boundary, but resets state on every invocation. Picking either one only solves half the problem.

The combination that actually works sits closer to containers architecturally, but adds the one thing containers lack: kernel isolation scoped to each individual workload. Platforms like Maritime put each agent inside its own persistent Firecracker micro-VM, so it gets the continuous session it needs, but a hardware-enforced wall keeps it apart from every other workload on the same host. What follows traces each place the serverless model breaks for agents, one failure at a time, and shows why that combination is what closes the gap.

Serverless cold starts compound across multi-step agent reasoning loops

A cold start that costs a few hundred milliseconds barely registers if it's just a single stateless web request. A user clicks, waits a beat, gets a response. Nobody notices or complains. An agent loop doesn't get that forgiveness, because the penalty doesn't reset between steps, it stacks. When a tool call triggers a fresh cold start, it adds its tax on top of every cold start that came before. If an agent strings together five sequential tool calls, it pays that tax five separate times, and the user feels the sum of all five, not the average.

Picture a fairly ordinary agent task: it writes a scraping script and installs the dependencies it needs, inspects what came back and edits some local files, then runs a cleaning function and produces a plot. That's three distinct turns through the loop, and each one depends on everything the turn before it built. If you want to hold onto installed packages, in-memory variables, and local files across those three turns, you need to stand up an external storage workaround for every piece of state. Absent that, each invocation risks starting over from an empty environment, so it reinstalls the same packages and rebuilds the same files it already built two steps ago.

Micro-VM architecture changes the shape of that latency curve. A Firecracker cold boot already runs faster than comparable Docker startup times, and snapshot restore pushes the number down further, into the sub-30-millisecond range. Platforms built around perpetual standby can resume an environment in the tens of milliseconds. Snapshot-resume is the baseline a sequential agent loop needs to feel responsive. Platforms built around this model can resume a complete agent, full filesystem and memory state intact, in under a second, and that shift from paying a cold-start tax on every step to a near-instant resume is what separates an agent that feels alive from one that feels like it's rebooting mid-sentence.

State loss between invocations

When a stateless function resets, it doesn't just drop a variable. It drops everything the agent accumulated to get to that point: installed packages, partially written files, the conversation's working memory, credentials and session tokens still valid from the step before. An agent needs all of that intact to take its next action, and pushing that state somewhere external doesn't recreate it so much as introduce a new set of ways for it to break.

The standard fix in serverless architecture is to serialize everything to S3 or a database between invocations and deserialize it at the start of the next one. That's the pattern most Lambda-based systems lean on for anything that needs to look stateful, and it works reasonably well for simple key-value data. It runs into real trouble with the kind of state an agent actually accumulates.

Filesystem state doesn't serialize cleanly. An agent's working directory after three or four steps might contain a mix of installed software packages, partially written binary artifacts, and text files in different stages of completion, and there's no straightforward way to flatten that mix into a key-value store and expect to get it back intact. Reinstalling dependencies at the start of every invocation costs time even when the underlying compute is already warm, because pip install still has to run even if the function itself didn't need to boot. Every round trip to that external store adds latency on top of whatever the tool call itself takes, and that latency builds up across the loop the same way cold starts do. Credentials present their own failure mode: a session token that was valid when it got serialized may have expired by the time the next invocation deserializes it, and the agent discovers this only when the next tool call fails.

A micro-VM avoids the entire category of failure by not requiring serialization. It keeps full RAM state, the local disk directories, the installed dependencies, and any background processes running for as long as the session lasts, so the agent resumes exactly where it stopped, with nothing to reconstruct. Snapshot-and-restore extends that same guarantee across idle gaps: a live checkpoint captures the running machine, memory and block device together, and restores it for the next invocation without the agent registering that any pause happened. Maritime builds this in as the default rather than an option: every agent runs inside its own persistent Firecracker micro-VM with its own disk, so files, credentials, and installed packages survive sleep and redeploy without any serialization step ever running in the background.

Shared-kernel containers do not solve the isolation problem agents create

Containers look like the obvious fix once you've seen how badly serialization handles agent state. Sessions persist, the filesystem survives a restart if you configure the right volume, and nothing forces a reset every few hundred milliseconds. Nothing about that picture is wrong.

It opens a different one. Every container on a given node shares the same Linux kernel, so if there's a single kernel-level vulnerability, one container can reach into its neighbors on the same host. That's a tolerable risk for a typical web application, where the code running inside the container is code someone on the team wrote and reviewed. It's a much worse bet for an agent, because an agent is executing code an LLM generated moments earlier, often without a human ever reading it, and doing so continuously and autonomously across many tool calls. A container escape against a reviewed web app is a serious incident. But if an agent is running unreviewed, LLM-generated code at high frequency across many users, a container escape starts to look like an inevitability rather than an edge case, given enough volume and enough time.

The deeper issue is architectural rather than procedural: namespace-based isolation, which is what a container actually is, lives in the same layer the agent's code can reach, userspace, Linux capabilities, cgroups. Hardware virtualization sits a layer below that, where nothing the agent can execute can reach it. For agents running untrusted or LLM-generated code, the practical guidance in the field is to use microVMs like Firecracker or user-space application kernels like gVisor rather than shared-kernel containers. Containers fail on isolation. Serverless fails on state. Micro-VMs are the one architecture built to answer both failures at once.

Firecracker's isolation model and how snapshot-restore makes it practical at agent latencies

A Firecracker micro-VM gives each agent its own dedicated guest kernel, isolated from every other workload on the host by a hypervisor boundary enforced in hardware rather than by namespace rules living in the same userspace the agent's code touches. A bug or exploit in one agent's kernel stays contained to that one VM. It has no path to any other tenant on the same machine.

That isolation gives an agent real room to work. It can install packages, write files to disk, launch background processes, open a browser session, or even corrupt its own environment through a bad command, and none of that reaches past the VM boundary into anything else running on the host. The agent gets the freedom a stateful workload needs without the shared blast radius a container carries.

Speed used to make this impractical: booting a full VM for every session sounds slow, and historically it was. Snapshot-restore is the mechanism that closes that gap. Instead of booting a kernel from scratch, the system captures a complete running state, memory and disk together, and restores that snapshot directly, skipping the boot process. Research published on this problem in 2026, under the name DeltaBox, pushes the mechanism further: it performs both an incremental CRIU dump for durability and a template-creating fork for low-millisecond restore at every checkpoint, and it hides both costs inside the window where the system is already waiting on LLM output anyway. Restore latency under that design gets so low that sandbox overhead becomes a negligible fraction of total execution time, so a user doesn't notice it.

AWS made a version of this pattern fully managed when it launched Lambda MicroVMs on June 22, 2026. Each session gets its own Firecracker VM with its own kernel, its own filesystem, and its own network namespace, and that state persists for up to eight hours. Sessions resume from a snapshot instead of booting cold, and billing stops the moment a session suspends. AWS built the feature explicitly for AI agents, developer platforms, and multi-tenant workloads, which is a tell about where the rest of the industry sees this problem heading.

Idle-cost economics determine whether per-user agent deployment is viable at scale

Agent traffic doesn't arrive evenly. An agent spends most of its time waiting, for a user to type something, for a session to resume, for the next scheduled task, and it spends the rest in short, compute-heavy bursts. Any billing model that assumes steady, predictable load is going to misprice that pattern badly in one direction or the other.

Serverless billing looks like a match for bursty compute at first glance, but the per-invocation model forces a choice between cold-starting on every burst or paying to keep a warm pool alive between them. Both options cost real money, and either one erases the billing advantage serverless was supposed to offer. Running a persistent VM continuously is worse in the other direction: an agent VM that stays on around the clock to serve a small fraction of actual active work ends up billed for the overwhelming majority of its runtime as pure idle compute, and the unit economics collapse before the product even reaches meaningful scale.

The trap appears in a common scenario: a team ships an agentic feature at a flat seat price, a small fraction of heavy users ends up driving most of the inference and compute cost, and within a few months that one feature quietly absorbs most of the infrastructure budget for a minority of total usage. If you fix it afterward, you're usually retrofitting per-tenant budget enforcement into a system that was never built to track cost at that level of granularity.

The structural fix is to boot once, checkpoint the moment the agent goes idle, destroy the running VM, and restore it from NVMe storage the next time it's needed. Under that model the agent pays for cheap storage while it's idle, orders of magnitude less expensive than compute, and pays for compute only during the time it's actually running. A persistent micro-VM has its own kernel and filesystem, so the agent never loses the installed packages, intermediate files, or in-memory context that an external store like S3 or a database can't reliably reconstruct on its own, and that continuity is what lets the idle-to-active billing split work without silently reintroducing a serialization step. AWS Lambda MicroVMs implements the same principle at the managed layer: once execution finishes, the MicroVM can enter an idle phase and automatically suspend its state if an idle policy (maxIdleDurationSeconds) is configured, so billing applies only to active execution time and stored snapshots, not continuous idle compute. That's the economic argument for per-user micro-VMs: the architecture that solves state and isolation also happens to be the only one whose billing model survives contact with real, uneven agent traffic at scale.

The per-user agent fleet as the right deployment primitive for agent-native products

One micro-VM per user session turns out to be the natural unit for building an agent-native product, not an implementation detail you bury under it. Each user gets an environment that belongs entirely to them: their own filesystem, their own installed packages, their own accumulated memory, walled off by hardware isolation from every other user's environment running on the same infrastructure. One user's broken dependency or runaway process never touches another user's session.

Serverless can't express this pattern without working against its own design. Invocations are stateless on purpose. Giving each user a persistent, isolated environment under a serverless model means bolting external storage, session reconstruction, and credential refresh logic on top of a system built to actively discard all three. Every one of the workarounds covered above, the serialization layer, the warm-pool cost, the shared-kernel exposure, comes back the moment you try to force per-user persistence onto infrastructure designed to forget. For a product whose entire value is a continuous, trustworthy relationship between one user and one agent, that's the only architecture that actually matches what the product is trying to be.

Sources

  1. DeltaBox: Scaling Stateful AI Agents with Millisecond-Level ...
  2. Firecracker

More in Sandbox & Runtime