Migrating a Lambda-Based AI Agent to a Persistent Runtime Without Rebuilding Your Product
Keep your APIs and agent logic while swapping out Lambda's execution layer.

Migrating a Lambda-based AI agent to a persistent runtime is an execution-layer substitution. Serverless functions fit short, stateless work, while agents that need a lasting workspace, human handoff, or long-running sessions need a persistent, resumable environment. Developers can keep application logic, event contracts, and APIs while changing the infrastructure that runs the agent.
Why Lambda's execution model breaks down when agents hold state and run long tasks
Lambda fits event-driven functions well. Its model assumes that code is stateless, invocations are short, and executed code is trusted developer-written code. An agent can violate all three assumptions during one task. It may need to preserve conversational context, wait through several model responses, and execute code generated by the model.
State is the first point of friction. Lambda initializes and invokes an execution environment, which may then be frozen or reused. Even with that reuse, memory or files may not persist across turns, so anything the agent needs later must live elsewhere. Environment setup can also recur across invocations, while a lasting workspace can incur that cost once.
Duration creates a separate constraint. Lambda Functions can run for up to 15 minutes, but multi-step reasoning or an interactive session can take longer. Lambda also charges for the full execution duration at the CPU-and-memory rate, including time spent waiting for model responses. Much of an LLM-based agent’s wall-clock time is I/O wait.
These limits leave the application layer to coordinate the work. Queues, external state stores, idempotency keys, retry handlers, and checkpoints compensate for the execution model. Some serve real product needs, but others exist only to reconstruct an agent’s working environment between calls. Lambda’s execution model is a poor fit for these workloads.
What a persistent runtime gives an agent that a function invocation cannot
A persistent runtime gives the agent a computer. That means a Linux environment with processes, files, terminals, open ports, and resumable state. The agent can install dependencies once, keep a REPL or development server alive, inspect logs, and retry failed commands. After a human reviews its output, it can return to the workspace.
Persistence comes in several different forms. Lambda MicroVMs, launched in June 2026, provide explicit suspend and resume, state retained across suspensions, and snapshot boot in seconds. AgentCore Runtime’s serverless tier offers managed session storage in preview but does not provide suspend and resume. AgentCore Runtime Instances, generally available in August 2026, support sessions up to 14 days and retain a persistent volume after a session stops.
Step Functions Standard Workflows can hold waits, retries, approvals, and checkpoints for up to one year, calling a runtime when work is ready. Lambda Durable Functions instead extend Lambda with checkpointed workflows that replay from the start while skipping completed steps using stored results. They support external-signal waits and charge only for active compute time.
These options solve different parts of the problem. Request timeout, asynchronous job duration, compute lifecycle, and logical session lifetime are four separate design axes. A longer workflow limit alone does not provide a live terminal, just as a persistent disk alone does not preserve running processes.
How to identify which parts of a Lambda-based agent are worth preserving
The migration audit starts with the caller’s contract. API Gateway routes, SQS triggers, SNS subscriptions, and EventBridge rules sit outside the agent’s execution environment. Those contracts can survive the move unchanged. The audit distinguishes the parts that describe how callers reach the product from those that merely accommodate Lambda.
Application logic is the next layer to inspect. Reasoning loops, tool definitions, prompt templates, and framework code in LangGraph, Strands, or CrewAI are portable unless they embed Lambda-specific handler signatures or assume ephemeral execution. The Lambda MCP Server illustrates preservation directly by turning existing Lambda functions into tools that any MCP-capable agent can call without rebuilding those functions. Existing serverless tools need not move with the agent that uses them.
State management needs a more selective review. DynamoDB, S3, or EFS may hold data because the product needs shared or lasting storage, or simply because Lambda cannot guarantee a lasting workspace. Only the second category is a candidate for moving into the runtime’s local filesystem. That distinction prevents a runtime migration from becoming an unnecessary storage rewrite.
Some execution assumptions will need to change. Handler entry points built around freezing and thawing, timeout budgets embedded in retries, and per-call environment initialization belong in that category. The audit separates those assumptions from the agent’s actual behavior before any substitution begins.
Replacing the execution layer in stages without changing the application interface

The team can deploy each of the three migration stages on its own. In Stage 1, the team wraps the existing handler and packages the agent code as a container image, including the Dockerfile and required artifacts. The agent runs on the persistent runtime, and the inbound API contract stays the same for the caller.
Stage 2 hands appropriate state back to the runtime. Session state moves to the persistent environment’s local filesystem, and the team can remove stores added only to work around ephemeral execution. Data still needs external storage if it must survive a full session teardown or be shared across sessions. Local state is not a replacement for every database.
Stage 3 extends duration and changes idle behavior. Lambda MicroVMs, AgentCore Runtime serverless, and Runtime Instances each provide the right execution model for different workloads at this stage. Where suspend and resume are supported, the runtime can stop compute charges during suspended waits and resume for the next turn. That behavior must not be assumed for the serverless tier, which lacks explicit suspend and resume.
Session identity becomes the link between separate compute lifecycles. Runtime Instances retain a persistent volume after a session stops and reattach it when invoked with the same runtimeSessionId, even on a replacement instance. For tasks spanning days or weeks, Step Functions Standard or Lambda Durable Functions can hold the workflow checkpoint while the runtime holds the working environment. Short, stateless Lambda functions for API processing, event transformation, and small tool calls should stay where they are.
Choosing the right persistent runtime tier for the agent's actual workload shape

Short, event-driven processing under 15 minutes belongs on Lambda Functions. Interactive or background sessions up to 8 hours can fit Lambda MicroVMs for isolated per-user code execution or AgentCore Runtime serverless for managed agent hosting. Sessions up to 14 days with persistent volumes fit Runtime Instances, while tasks spanning months need an outer orchestrator such as Step Functions Standard.
State and resources refine that initial choice. MicroVMs fit work that needs explicit snapshots of memory and disk, the serverless tier fits work that needs managed session storage without suspend and resume, and Instances fit work that needs to keep volumes after an instance stops. The latter offers EC2-backed GPU-accelerated, memory-optimized, and compute-optimized families. Its bill includes the EC2 cost and a management fee.
A session dominated by model waits or human review benefits more from suspension than one that keeps its CPU busy. MicroVMs stop compute charges while suspended, but snapshot storage continues to cost money. Sleeping compute is not free storage.
Operations ownership is the final dividing line. AgentCore manages session routing, scaling, idle-session teardown, authentication, versioning, and endpoints, with observability and MCP/A2A protocol support for managed hosting. MicroVMs provide the VM itself and require more assembly. Teams that want managed agent hosting should lean toward AgentCore, while those that need raw VM access or low-level network control should lean toward MicroVMs.
Sandboxing agent-generated code once the execution layer is persistent
Persistence makes the workspace useful and more sensitive. It now holds the agent’s credentials, memory, and session state across turns. If generated code executes inside that same trusted environment, it can reach those assets. Moving away from disposable invocations therefore creates a security responsibility that must be addressed before production.
Untrusted code needs a separate execution boundary. The sandboxing options here are a hardware-isolated Firecracker micro-VM or a container running under gVisor through its runsc runtime, providing isolation beyond a shared-kernel Docker container alone. Lambda MicroVMs provide hardware-isolated sessions for generated-code execution. That separation protects the agent only when its credentials remain outside the untrusted code’s environment.
Arbitrary or user-supplied code needs full VM isolation, while low-risk tool calls that are well understood can use lighter isolation that fits their threat level. At scale, the sandbox must also cope with thousands of concurrent execution requests in large multi-turn RL rollouts. Uncontrolled threads and hard-to-kill library calls must not stall the main process.
Session isolation also has a governance role. AgentCore assigns each runtimeSessionId a dedicated micro-VM and sanitizes memory on termination. For workloads handling patient records, financial documents, or legal materials, that makes session design part of the data boundary. Teams must decide which records are allowed inside that boundary together.
Governance and compliance considerations specific to persistent agent sessions in regulated industries
Teams must decide which sensitive data to keep in persistent sessions. PHI, PII, financial records, and privileged legal material can remain in a workspace beyond a short invocation. AgentCore isolates each session’s memory and disk from other sessions and sanitizes memory when the micro-VM terminates. Persistent volumes that are kept need their own review even when memory has been sanitized.
One document per session works for independent patient records or separate legal matters that must not share context. One session per batch works for related documents, such as a case file or loan application package, that the agent must reason across. Isolation does not decide which grouping is appropriate for the workload.
Audit records need deliberate configuration as well. AgentCore session invocations generate CloudTrail data plane events including InvokeAgentRuntime, InvokeAgentRuntimeCommand, and InvokeAgentRuntimeCommandShell, but these must be enabled explicitly. CloudWatch provides per-invocation operational logs. Teams that must demonstrate what data reached the agent and when need a supplementary audit trail.
AgentCore supports payloads up to 100 MB, but structured extracts can avoid exposing entire raw documents when they are unnecessary. Computer-use agents introduce another exposure because screenshots of EHR systems, payer portals, or legacy desktops travel to the model. Those workloads need network egress controls, session logging, and human takeover as operational controls.
What to expect from the agent after migration: persistent state, human handoff, and long-horizon tasks
A coding agent can keep its working tools alive. Its terminal, open files, dependencies, and development server can persist across turns, allowing a human to reattach without reconstructing the workspace. Where VM snapshots are available, the agent can save a starting state before a risky change and branch to compare alternatives. That also supports evaluation pipelines and RL exploration without replaying the full setup.
A support agent gains continuity through human review. It can pause while an operator assesses an ambiguous result, then continue with the same session state. For a computer-use agent, a persistent desktop lets the operator review, correct, and return control on the live machine.
Longer sessions also need ongoing checks for degradation. The operational response is fast evaluation on every deployment, nightly regression suites using an LLM judge, and production drift alerts. Per-invocation logs alone cannot keep track of how well the agent is doing over time.
The largest change is the per-user machine model. With a suspendable runtime, each user can have an isolated environment that sleeps when idle and wakes in roughly one second, with compute metered by use and snapshot storage charged separately. A cron trigger, webhook, or human message can wake the agent to work with its signed-in browser, open files, and processes preserved. The product can wake the user’s existing worker for every event.


