Migrating a Browser Agent From Lambda to a Persistent VM per Agent Without Rewriting Your Agent Loop
Swap the infrastructure under your browser agent, not its loop, and keep sessions alive.

Migrating a browser agent from AWS Lambda to a persistent VM per agent is primarily an infrastructure change. Serverless functions fit stateless requests, while browser agents need a session that preserves running tools, files, and browser state across turns. The migration changes provisioning, lifecycle management, and state storage while leaving the model calls, tool interfaces, and decision loop intact.
Why Lambda's shape is wrong for browser agents, not just too short
A browser agent holds cookies, logged-in sessions, cached pages, downloaded files, and an open browser process while it works. Lambda’s execution model moves through initialization, invocation, and shutdown, with possible freezing between calls. That suits request-oriented work, but it gives a session-oriented agent no dependable claim on the same running environment for its next turn.
The 15-minute limit is only the visible symptom. A task can finish within that limit and still need its browser state for a follow-up instruction. A frozen environment is not an actively running browser, and a recycled environment cannot provide the previous process.
Freestyle describes an agent’s natural unit of work as a session in which it explores, makes mistakes, starts long-lived tools, reads their output later, and changes strategy. When that session runs through repeated function calls, the application code has to manage its state. Checkpoints, queues, idempotency keys, and retry handlers then accumulate to compensate for the runtime. Some remain useful for other reasons, but preserving a browser should not require rebuilding a computer around it.
What a browser agent actually needs from its runtime
Process continuity comes first for a browser agent. The browser needs to stay available between turns and keep its page state and authentication context so the agent can carry on without having to re-authenticate and re-navigate. A follow-up instruction must reach that browser. The runtime therefore needs an addressable session that can live on apart from the client connection.
Durable files are a separate requirement from running processes. An agent that writes code and also drives a browser needs project directories, browser profiles, downloads, and cached pages. Lambda’s /tmp is temporary scratch space. Freestyle’s model gives the agent a real Linux filesystem in place of an object-store abstraction. That distinction lets tools work against files in the environment where they run.
A real terminal completes the runtime requirement. Package managers ask questions, REPLs keep values in memory, and development servers stream logs after the command that launched them. When every interaction is a separate invocation, terminal state has to be kept outside the machine. Freestyle’s PTY sessions survive client disconnects, VM suspends, and forks because they are long-lived session objects.
What changes when you move to a persistent VM per agent: the infrastructure layer only
The execution environment becomes a micro-VM with its own kernel, persistent filesystem, and addressable network endpoint. Lifecycle code creates, runs, suspends, resumes, and terminates that VM. Browser profiles, cookies, and session tokens can stay in its persistent filesystem.
The agent loop remains the stable layer. Its sequence is still a model call, tool selection, tool execution, an observation, and the next model call. Navigate, click, type, and screenshot keep the same interfaces, although their implementations connect to an existing browser. The model endpoint, message format, prompt structure, and conversation-history structure can all stay the same.
Browser Use’s migration account illustrates this separation. It moved from a browser-only Lambda environment to running the whole agent in a sandbox that talks to a stateless control plane. The provisioning and lifecycle code changed while the agent loop stayed intact. Its FastAPI control plane holds service credentials, proxies LLM calls, and owns conversation history. That is one useful hybrid pattern, with persistent tool execution behind a stateless service, rather than a requirement to rebuild every part of the application.
The micro-VM mechanics that make persistent browser state practical
Firecracker micro-VMs make it practical to give each agent its own machine without keeping every machine running all the time. Each agent gets hardware-isolated compute with its own kernel, and sleep and wake let its session last beyond the time it spends using active compute. That distinction fits browser work particularly well. An agent often waits for a model response or a person before it can take its next action.
Snapshots reduce repeated browser setup as well. An environment can be prepared with the browser open, logged in, and at a known page, then restored or forked for a session. Browser Use describes suspending idle sandboxes and waking them for follow-up tasks so they avoid using compute while they wait, as machines that run all the time would.
A persistent ext4 volume can retain browser profiles and downloads after the instance itself has terminated, then attach to a replacement instance. That preserves disk state alone. Forking creates a new VM from the current running state, so the agent can try other navigation paths from the same authenticated environment in the middle of a session. These mechanisms support different forms of continuity and should not be treated as interchangeable.
Sandboxing the browser agent: why the security boundary moves, not disappears
A persistent VM places isolation at the VM’s kernel and network perimeter. Lambda isolates invocations, but a short invocation lifetime is not an access policy. A browser agent still needs limits on what its code can reach and whose credentials it can use.
Browser Use implements those limits through two separate boundaries. VM isolation contains code execution and separates agents from the host and other VMs. Identity and egress controls restrict access beyond that environment, with secrets held in the control plane and outbound traffic governed by an allowlist. Neither boundary substitutes for the other one.
The sandbox receives a session token, control plane URL, and session ID rather than cloud credentials, database passwords, or model API keys. Calls to external LLM and file-storage services go through the control plane, which holds the real credentials. Those service secrets are separate from the browser authentication state that a signed-in website needs. For sensitive screens such as EHR portals or financial dashboards, the architecture also supports routing within a customer’s network perimeter. BAAs and recording-retention policies remain separate requirements.
How to run the migration: the four concrete changes and the one thing you don't touch

To put this architecture into practice, make four infrastructure changes while leaving the agent loop alone. First, replace the Lambda invoke call with a VM create or resume call that returns a VM handle. Store its ID and endpoint in the session record so later turns reach the same environment. At session end, suspend or terminate according to the lifecycle needed. A suspended session should resume from its preserved state.
Second, move browser startup into VM provisioning or snapshot preparation. Launch the browser and navigate to the starting URL there, then give the loop a handle to the running browser. Authentication and cookie loading should happen when the browser is prepared or restored. The loop should not own the boot sequence. This keeps machine setup separate from the agent’s decisions about what to do on a page.
Third, put the secrets for services in a control plane. Give the sandbox its session token and control plane URL, and keep API keys, cloud credentials, and database passwords outside it. Send LLM calls through that service as a proxy and let it own the conversation history. This makes the sandbox replaceable without making it the authority for credentials or conversation records. Its browser workspace can still persist independently.
Fourth, replace temporary scratch storage with a persistent workspace volume mounted at a path that stays the same, such as /workspace or /persist. Put downloads, browser profiles, and session artifacts there so they survive suspend and remain available on resume. Keep model calls, tool dispatch, observation handling, and loop termination as they are. Browser tools may need new code to connect, but their interfaces stay the same. Browser Use’s DirectGateway for local development and ControlPlaneGateway for production provide a clean abstraction that keeps environment-specific wiring out of the loop.
Choosing where to provision the VM: persistent computers and the other options
Maritime provides persistent Linux agent computers built on Firecracker micro-VMs, plus Windows desktops and Android phones as full VMs, with retained workspaces, signed-in browsers, and built-in human takeover. Its agent boxes sleep when idle, wake in about a second, and use flat monthly pricing with no extra sleeping-machine charge, while sandboxes and on-demand desktops are billed per second while running with no minimum.
Those product types serve different lifecycle needs. Persistent boxes keep state across sessions, while throwaway sandboxes suit one-off tasks and eval runs, including parallel eval and RL work. Human takeover gives browser agents a handoff when they encounter CAPTCHAs, 2FA prompts, or ambiguous interfaces. Customers can bring their own model keys or use the built-in LLM proxy. The platform runs the computer, leaving room for the customer’s control-plane design.
Freestyle offers hardware-virtualized Linux machines with API control over files, commands, terminals, networking, domains, and lifecycle operations. Its durable PTY sessions and running-state forks work well for agents that use a browser, write code, and work in a terminal. Its strongest distinction here is control over a Linux session and its branches, with Windows and Android support unspecified in the supplied material.
AWS Lambda MicroVMs are distinct from standard Lambda functions. They run on Firecracker and offer IAM integration and VPC attachment for agents accessing private AWS resources. The charge is per instance-second, even when the machine is idle but still running, and the runtime has an 8-hour limit. Suspension preserves memory and disk, but termination releases resources without a persistent volume that reattaches afterward.
AWS AgentCore Runtime Instances are generally available as of August 2026 and support sessions up to 14 days. Their persistent volumes survive termination and reattach when reinvoked with the same runtimeSessionId. They provide managed EC2 compute integrated with AgentCore APIs, Identity, and Observability. The choice depends on the idle-cost model, the need for Windows or Android, and the compliance requirements that apply. A flat-price persistent computer with desktop support and available BAAs is a natural fit when those criteria outweigh deeper AWS integration.
What the migration does not solve, and when to stay on Lambda
Lambda remains a good fit for genuinely stateless work. Single-turn classification, webhook handling, and short transformations do not need a machine waiting for the next browser instruction. Existing IAM policies, VPC attachments, and operational work also count against migration when there is no clear per-task benefit. For CPU-bound batch transforms, cost modeling may show that VM metering offers no savings over invocation pricing.
Persistence does not improve the model’s judgment. Prompt engineering and eval harnesses remain necessary, and VM isolation does not replace identity or egress controls. Tasks spanning many days may still need durable orchestration above the compute layer. Step Functions Standard, for example, can run a workflow for up to a year while calling the runtime only when needed. A VM manages the execution environment.
The investment pays forward to later agents and task types. Once lifecycle management, session records, workspace storage, and the control-plane boundary are in place, those additions become configuration. Persistent VMs, sleep/wake billing, and control-plane secrets are emerging defaults for session-driven agent infrastructure. They give the agent a durable place to work without making its loop responsible for rebuilding that place on every turn.


