Why Self-Hosted Agent VMs Win Every Technical Constraint That Serverless Imposes
Self-hosted VMs solve the core mismatch between serverless platforms and long-running AI agents.

Persistent AI agent infrastructure and serverless functions run work in different ways. Self-hosted agent compute environments address the limits that interrupt long-running agents by providing persistent state, unrestricted task duration, snapshot-based wake, per-agent kernels, and control over dependencies. The advantage is architectural rather than a hosting preference, and managed VM-based runtimes can provide the same foundation without requiring every team to operate its own virtualization stack.
Why serverless and AI agents are structurally mismatched, not just a poor fit
An agent works in development, then reaches production and loses context or times out. The failure exposes a difference in execution models. Serverless was designed for short, stateless request-response cycles, while agents observe, reason, act, and repeat. A web application may return a response in milliseconds, but an agent request can involve multiple LLM calls, tool invocations, memory retrievals, and parallel subtasks before producing an answer.
Hosting that workflow means keeping a harness, a model, and state available together. State extends beyond the current context window. It includes conversation history, task progress, files, and credentials that the next step may need. An execution model that does not preserve this continuity forces the application to reconstruct it, so the mismatch cannot be resolved through timeout tuning alone.
Why do long-running AI agents fail on serverless execution limits?
Google Cloud Run and Cloud Functions 2nd gen impose default execution timeouts that can be extended only to platform-defined maximums. Cloud Functions 2nd gen has a shorter default timeout than Cloud Run. Azure Functions caps HTTP-triggered invocations at 230 seconds regardless of the configured function timeout because of the platform's load-balancer idle-timeout default. Configuration therefore has a fixed outer boundary. An application can adjust its execution window, but it cannot remove the platform's limit.
An agent may need more time than that window allows. A code-review agent may need to start sandboxes, fetch repositories, parse diffs, and call external services before it can complete one coherent assignment. Each operation belongs to the same task, even when it uses a different tool. Long reasoning loops give the agent more work to do before it finishes. If the agent outlives its execution window, the function provides no native mechanism for resuming the process from its interrupted position.
With VM-based execution, the process is free of that platform-imposed deadline. The agent can run until it completes, sleeps, or is explicitly stopped, rather than treating the function timeout as a task boundary. Managed agent runtimes that use that execution model can let the agent run this way too. Duration, however, is only the first constraint. Even when a workflow fits within each execution window, it needs to keep state across invocation boundaries, and serverless requires that state to be stored elsewhere.
Why statelessness between invocations is more than an inconvenience for agents
AWS resets execution environments on timeout, discarding the agent's in-memory state. Conversation history and task progress cannot depend on that environment surviving. The dependencies and credentials that later work needs must also be kept across the invocation boundary. This is not a missing configuration switch. Serverless applications must explicitly preserve whatever the next invocation needs to reconstruct the agent's working context.
S3 or DynamoDB can provide that external durability layer, but storage alone does not define how an interrupted agent resumes. The application must serialize its state, retrieve it, and keep the logic that lets work pick up from the saved progress. Reads and writes add round-trip latency to agent steps. That engineering cost recurs as the agent changes. A VM instead provides persistent disk, a filesystem, and process memory as native parts of the execution environment.
This distinction also separates model hosting from agent hosting. SageMaker and Vertex AI address model-inference infrastructure, which is not the same question as where an agent's process lives and remembers its progress. Containers address this continuity problem better than functions because sessions can persist and filesystems can survive restarts with the right configuration. Containers can support stateful work, but they still have a gap in isolation.
Snapshot-restore scheduling extends VM persistence to paused execution. The working directory, installed dependencies, running processes, and warm page cache can be frozen when an agent sleeps and restored when it wakes. For that pause-and-resume operation, an external durability layer is unnecessary. The same mechanism also changes how much delay a user experiences when work continues.
What cold-start and wake latency actually cost agent products that need to feel responsive
A cold start makes the work wait before it can begin. In a single-request web application, that penalty may occur once on the path to a response. An agent that makes tool calls in sequence can face that delay at several invocation boundaries, so the user may have to wait several times in one interaction. A startup cost that is tolerable in isolation can become disruptive when several steps incur it.
Serverless cold starts vary substantially by runtime, with some cases taking little time and others exceeding a second. Tuning the application alone cannot remove those differences between runtimes. A peer-reviewed USENIX ATC 2020 study measured container cold starts in the mid-hundreds of milliseconds, which can also be significant in latency-sensitive agent workflows. Containers are not a zero-latency alternative. End-to-end comparisons also show that Firecracker cold boots take longer than Docker container startup times.
Firecracker's latency advantage for persistent agents comes from snapshot restore instead. In a template-based snapshot model, the full kernel boot happens on the first spawn, and later wakes restore the saved execution. That distinction changes the relevant measure from boot time to wake time. Copy-on-write memory sharing makes this practical at fleet density because hundreds of sandboxes restored from the same base image can share physical pages they have not yet modified.
Human-facing workflows make the benefit particularly clear when an agent pauses for input and resumes after the user responds. Sub-second wake preserves the sense of an ongoing interaction. Responsiveness depends on continuity as well as speed. Yet latency and lost state are visible failures that users or developers can notice directly. The next constraint, isolation, is less visible and potentially more dangerous when the agent executes code.
Why shared-kernel containers do not provide the isolation that code-executing agents require
Containers can support long-running processes and persistent state, but every container on the same node uses the same Linux kernel. For agents that run LLM-generated or untrusted code, sharing that kernel means sharing a blast radius. A kernel vulnerability can expose workloads beyond the container in which exploitation begins. Control over a container does not remove that boundary. Coding and data-analysis agents thus need their isolation checked as well as whether their sessions stay alive.
Google's CNA assessment scored the Linux kernel eBPF flaw CVE-2023-2163 at 10.0 CRITICAL. The NVD describes the flaw as permitting unsafe code paths that can lead to arbitrary kernel-memory access, privilege escalation, and container escape. The runc container-escape bug CVE-2024-21626 scored 8.6 HIGH. These are documented vulnerabilities. Their relevance is structural rather than a claim that every container deployment is compromised.
AWS Lambda uses Firecracker micro-VMs with hardware-level virtualization, demonstrating that serverless can provide strong isolation even while retaining execution and continuity constraints. Firecracker gives each workload its own guest kernel rather than placing agents against one shared workload kernel. A guest-kernel exploit therefore does not, by itself, become an exploit of a kernel shared with neighboring agents. That is the crucial boundary change. Firecracker's Rust VMM, deliberately small device model, and less than 5 MiB memory overhead per VM make this isolation model practical at high concurrency.
The relevant unit of isolation is the agent session. When several agents run inside one operator-controlled environment, each does not automatically get its own hardware-enforced kernel boundary. A self-hosted VPS or container offers stack control, but that is a different property from per-agent isolation. Micro-VMs combine the persistent execution of containers with separate guest kernels. Once that boundary is in place, the remaining question is how freely each agent can change its own environment.
How serverless dependency lock-in constrains the agent's ability to install, configure, and rebuild freely
Serverless platforms run agents in managed execution environments that limit what they can install, how long processes can run, and their kernel-level access. That suits functions whose dependencies and behavior are defined before invocation. Installing packages, running browser sessions, and starting arbitrary processes can be part of the task itself.
An agent that reinstalls dependencies on each invocation pays setup time again and depends on the network being available during that setup. Persisting the installed environment removes this reconstruction step, while a separate guest kernel provides a boundary within which the agent can install, break, and rebuild without sharing a workload kernel. Persistence and isolation serve complementary purposes here.
A micro-VM gives the agent persistent disk and the privileges to install packages, run browser sessions, and start arbitrary processes within the guest. Those capabilities give the agent control over its own environment while preserving the separation established by virtualization. That distinction makes environment freedom compatible with per-agent isolation. It also explains why a shared namespace is not an equivalent foundation for autonomous code execution.
Operating that foundation directly has a real cost. Firecracker requires host networking work involving TAP interfaces, IP tables, and routing, unlike Kubernetes environments supported by mature CNI plugins. With self-hosting, the operator must handle networking and scheduling. The conclusion is not that every team should run its own VMM. A managed VM-based agent runtime should absorb that complexity and let developers move from code to a live API endpoint in a single push, leaving the architectural choice distinct from the operational one.
What the right agent infrastructure looks like once all five constraints are taken seriously
Meeting all these needs calls for persistent micro-VMs with snapshot-restore scheduling and per-agent kernel isolation. Each agent has a Firecracker micro-VM on bare metal, with persistent disk and control over its guest environment. Execution lasts for the task. Sleeping preserves the process for a sub-second wake instead of forcing reconstruction, while separate guest kernels let code-executing agents operate without sharing the same kernel boundary.
The economic model depends on how little time most agents spend actively computing. Snapshot-restore scheduling turns idle compute into near-zero storage cost, allowing a fleet of thousands of agents to incur compute costs that track active concurrency. Flat-rate economics can follow that active footprint. Human-in-the-loop work exposes the difference clearly because an agent may wait for seconds or hours before proceeding. Charging that wait to storage instead of running compute makes prolonged pauses practical at scale.
One agent per user becomes a workable building block when agents that are idle need no live compute. Tooling should preserve the same separation of responsibilities through a CLI for local processing and direct service integration, with MCP servers providing network-isolated extensibility boundaries. Across those network boundaries, tool calls can be firewalled, rate-limited, and audited, while new tools can ship without redeploying the orchestrator. Buyers still need to decide who operates this persistent VM foundation.


