# Lambda MicroVMs and durable functions: a sandbox for agent code

> Lambda durable functions can now orchestrate Lambda MicroVMs in developer preview: checkpointed, retried, parallel sandboxes for AI-generated or untrusted code. What it is, how to design it, and how to draw it.

## Key takeaways

- Lambda MicroVMs run untrusted or AI-generated code with VM-level isolation, built on Firecracker.
- A durable function can now launch MicroVMs, run each task as a checkpointed durable operation, retry failures and run several MicroVMs in parallel.
- The orchestration is a developer preview for the TypeScript and Python Durable Execution SDKs. AWS says not to use it for production workloads.
- On a diagram, "the agent runs code" becomes three things: a trigger, an orchestrator and a sandbox with its own network rules.

[Open this diagram in archhy](https://archhy.com/app#d=N4IgLglmA2CmIC4QBkCGBbARgE1QAmwFcAnVTOPAM0IDsBjSAexoGc9Hi6ALWFsUyDQDmeALIQ6xRgDVReFqhrZMjAB688ACmywAbrGiMADrGJ4jxPRFgB3AJQgANCGioAno0JgAIhEsMIZkQUACUnEHRYMFREUCFDTFRoFliQUghoAGUwNzhgujhFcJpGHUyIAC94JHRwowkwEmrQSBhq-kJYAF8e5xKdFIQAbVAIbGDWvOcck2DvUhsIYXCWLlRZmtRiAGtsRhsacMUS6KYaAGkl8c2dvYPwlVVs3OrwKCmQVDo6WBowAGFGIZiMEAMSUSgATkhAAYYeFXJgDME0FhcAQSGQKNR6Gc2BxuLx+KhBCJxJIZHIFEpHhptHoDMZTOZLLprPYADo0ACCAHVMgQGYYTGYLFZbHgAO14WgdPiwbB4OilWB4JZiCRSWQsRx4Yi0PCYNx4fBEUjkVU4gJBZyUDLQQHAsEQl2UB4cHTER0cMF0HAAVlgAEZ3cRPbyxmAuIgg84VGHTCFUNgIIRBgAOaawVQAoE+pCgmGUIMAdgATDFbcwwOUqogy2WsznudAIEJDkg4JQwOF9MRIHQki22x2ImNsB9jF8oG4Y85XB4vKlVIgYc5ZwgALRlgDMjZAi2wUcQ0LXIB4ba4PYQJYALM4KgBJJTZxD+3qja5pWAAR068pBaY3A2EAAFUWFMBEyGRJBuSEX4wHYMx-kfPAACtGEwKD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zNKoiQBFX-pEFgCh7afGIFIGw+0lATC2ooeI5itiVOyFsa8IASjOxWJIn4AAJTuM8QAsE3FtY+0wtjwTAH0pQAywCbi7D2W0EB1DYHKAMRAHRuiW1SYwdJ35MkL0AuAHJSB1r+RDp-Q6CEjgVP2NUr8-AID1I+E0-YLT+zBA6eYlg3TYBTInK8IZYBjBc3GVEP5My5mwG7OEO0yzVm8HWfqTZoBtm7NSulY5IBMbgxJJDeGn8CojPgocl5VSalIAeU8xpNybBvLaZ8rpJBen9IBcM3qYziATPBa8WZ8yYVLIVPCwYGyK4pLSYNI6YAMXBGxcSIFhzzmFSJZBZwpK7m1MecIZ5NK6UfOYF8n53L2ZstGeAUFkyWUTE3ECow-K4VjARQgEVWzxVVz5kc4IkcymKqQMdQgGRFSd3kHHIwCcFnlMqeqildStXUuadEd5SAGVe0NZaquJraIcq5Wm8AkLoWLPtWsp1SLRWoplZwMGcq8VAuCIgy++SQgGj-tsXULFUBQD1LwK64a1XkvADGhpjLOC-JzUMkZmazWcrBTm3lULw2wsFQ64VJaXU7PLYSHF8rsm1qQQ2g06obpJDgIJVVNKo39s1YO098bWl6s6SmplI7pmspUPPNdWbp3PqtXygti6i3OpRa68+9bpiYuMaYhe+TpF4DspYEpSpmAJK3fOJYsBp6vFwKsRe17bl9spbG65N7E3tP1UO5lX703jvDQm7NFHc0-pSQKlZS7EWdFLUBr15ia1V1AbQ-F0NUZcBg18ITzaESofQ8ETDPBxK9vuQO7VRH6WkYfcOo1lH2WTto-8q1r6gW1F-cx-9JaoldCAA)

An AI agent that writes code needs somewhere safe to run it. The week before re:Invent, AWS put a new answer on the table: Lambda durable functions can now orchestrate Lambda MicroVMs, in developer preview. The durable function is the orchestrator, with checkpoints and retries, and each MicroVM is a sandbox with its own kernel. It was one of seven launches in {{link:post:aws-agent-plumbing-before-reinvent-2026}}. This post looks at it closely: what it is, how to design it, and what changes on your diagram.

## The problem: code you did not write, running next to code you did

Agents, CI systems and scanners run code nobody on your team has read. If that code runs in the same place as the agent, it can reach the agent's state, its credentials and other users' work. So it needs its own boundary.

A boundary is only half the job. Someone has to start the sandbox, hand it a task, notice when it stalls, retry it, collect the result and shut it down. If that control code crashes halfway, you lose track of which sandboxes are still running.

## What Lambda MicroVMs are

Lambda MicroVMs are a serverless compute environment with VM-level isolation and full operating system features, such as installing system packages or mounting file systems. They run on Firecracker, the virtualisation technology that already runs Lambda functions.

The lifecycle, as the documentation describes it:

1. You upload your code and a Dockerfile as a zip archive to Amazon S3.
2. You ask Lambda to create a MicroVM image. Lambda runs the Dockerfile, starts your application and takes a snapshot of the initialised environment.
3. When you need a sandbox, you call `run-microvm`, and Lambda launches a MicroVM from the snapshot.
4. Clients reach it at its own HTTPS endpoint.
5. When it is idle it can suspend, keeping memory and disk state, and resume when traffic returns.
6. When the work is done, you terminate it.

Every request to a MicroVM endpoint needs a token from `create-microvm-auth-token`. The token is encrypted (JWE) and scoped to one MicroVM, a set of ports and an expiry time. A MicroVM can also run with no inbound connectivity at all.

## What durable functions add

A durable function is a Lambda function that checkpoints its progress. When it resumes after a wait or a failure, it replays from the start and skips the steps that already finished, using their stored results. Executions can last up to one year. Each invocation is still capped by the function timeout, now 30 minutes on demand ([what changed with the 30-minute timeout](https://gazeek.com/blog/lambda-30-minute-timeout)); the checkpoints carry the job from one invocation to the next.

The new extension adds durable operations for MicroVMs. The durable function manages the MicroVM lifecycle and runs each task as a durable operation. It checkpoints progress, retries failed tasks and refreshes MicroVM tokens as needed. A task can run in its own MicroVM, or in a shared MicroVM session where tasks share files and memory. One durable function can run several MicroVMs in parallel, and it can be started from event sources such as Amazon SQS or Amazon EventBridge.

Inside the MicroVM image you add an optional worker library. It receives tasks, sends heartbeats and reports results back to the orchestrator.

## How to design it

Think in three parts.

- **Trigger.** A queue or an event rule hands work to the orchestrator.
- **Orchestrator.** The durable function decides how many sandboxes to run, which task goes where, and what to do when one fails.
- **Sandbox.** Each MicroVM runs one task, or one session of related tasks, then ends. Use a shared session when steps need the same files, such as installing dependencies and then running tests.

Then decide the sandbox's network. By default a MicroVM has public internet access on the way out. To reach private resources, you attach a VPC egress network connector, and the traffic follows your security groups and network ACLs. For production workloads, AWS recommends restricting outbound traffic with a network connector so a job can only reach what it needs. Shell access exists for development and troubleshooting, and AWS says not to attach it to production MicroVMs.

Finally, the permissions. AWS's advice for its GitHub runner example is to scope the MicroVM's execution role to only what the job needs, because the role is the blast radius of whatever code runs inside.

## What changes on your diagram

Draw it like this:

- An SQS queue and an EventBridge rule on the left, both pointing at the orchestrator.
- The durable function in the middle, labelled as the orchestrator.
- A boundary labelled as the sandbox, holding one MicroVM card per parallel task. The arrows into it say "run task" and the arrows back say "heartbeat and result".
- An S3 bucket and a MicroVM image feeding the sandbox, because every MicroVM launches from that snapshot.
- A dashed arrow from the sandbox through a VPC egress connector to the one private resource it may reach.

Anyone reading it should see where untrusted code runs and what it can touch.

## When to use it, and when not

Use it when you run code you did not write: agent-generated code, pull requests from forks, user notebooks, or scanners that open untrusted files. Use it when a multi-step job must survive failures, or many sandboxes need one controller.

Do not use the orchestration for production yet. It is a developer preview, and AWS says preview features may change. If your workflow mostly connects AWS services and you want a visual designer, AWS's own comparison points to Step Functions instead of durable functions.

## Cost and limits, as AWS states them

MicroVM compute is billed per second, on baseline and peak use. You provision a baseline size, and a MicroVM can scale up to four times that baseline during peaks. Snapshot operations, snapshot storage and data transfer are billed separately. A suspended MicroVM has no compute charge, and its full memory and disk state is kept. A MicroVM lasts up to 8 hours, running and suspended together. The orchestration extension is available in every Region that supports both Lambda durable functions and Lambda MicroVMs.

## Frequently asked questions

### Is this ready for production?

Not the orchestration. Durable functions orchestrating MicroVMs is a developer preview for the TypeScript and Python Durable Execution SDKs, and AWS says not to use preview features for production workloads.

### Why not just run the generated code inside the agent's Lambda function?

Because the code would share a boundary with the agent. A MicroVM gives it its own kernel, memory and disk, in a separate execution boundary with no access to the agent's state.

### Can a MicroVM reach my VPC?

Yes, through a VPC egress network connector you create and attach when the MicroVM runs. Without one, outbound traffic goes to the public internet by default. AWS recommends restricting outbound traffic for production workloads.

### What happens if the orchestrator fails halfway through?

The durable function checkpoints each task as a durable operation. When it resumes, it replays and skips completed work, and it retries failed tasks.

### What does an idle MicroVM cost?

A suspended MicroVM has no compute charge. Snapshot operations and storage, and data transfer, are billed separately.

*Based on:* The AWS What's New announcement from November 2026 on orchestrating MicroVMs with Lambda durable functions, the AWS Lambda MicroVMs product page, and the AWS Lambda Developer Guide pages on MicroVMs, MicroVM networking, durable functions and the GitHub workflows integration.
