DEV Community

Cover image for Running AI-Written Tests in Throwaway MicroVMs with Durable Lambda
Sascha Mirow-Stanitzok
Sascha Mirow-Stanitzok

Posted on Originally published at sascha-ms.de

Running AI-Written Tests in Throwaway MicroVMs with Durable Lambda

Imagine an AI coding agent that proposes patches for your app and writes the tests to go with them. Before anyone reviews the change, you want to know whether those tests even pass. But you really do not want unreviewed, machine-written code running in your normal CI or inside a Lambda function with broad permissions. Tests can execute anything.

That is the situation where a throwaway, VM-isolated sandbox makes sense. Building the sandbox itself is not the hard part. The hard part is the orchestration around it: who starts it reliably, hands over the work, waits for the result and makes sure it is torn down when something goes wrong?

On November 25, 2026, AWS shipped a developer preview that answers exactly that question. I walked through it in detail in my full article on Durable Functions and MicroVMs, including a complete patch check built with TypeScript and AWS CDK. Here is the condensed picture.

Two building blocks, one new glue layer

Lambda durable functions are regular Lambda functions that checkpoint their progress. If something fails, completed steps are replayed instead of re-executed, and a workflow can stretch over up to a year. Lambda MicroVMs are a Serverless compute environment with VM-level isolation that boots from a snapshot almost instantly and can be suspended with memory and files intact.

The new package @aws/durable-execution-sdk-js-extensions (subpath compute/microvm) connects the two. A small companion, @aws/durable-execution-sdk-js-compute-worker, runs inside the MicroVM, accepts jobs, sends heartbeats and reports results. Both are available for Python as well.

The detail I like most: while the MicroVM is busy, your function is not. It has ended and waits on a durable callback, so a 40-minute build does not cost you 40 minutes of Lambda compute.

Picking the right operation

You get two ready-made operations, and the choice is simpler than the names suggest:

  • microvm for exactly one job. Launch, hand over input, wait, shut down. Small payloads can even travel with the launch call itself, so the machine needs no inbound network access.
  • microvmSession when several jobs should share files and processes, for example clone, build, test. Each job becomes its own durable step, and you can even put waits or approvals between them.

For the patch check, two jobs share one machine: one writes the agent's files, the next runs the Node.js test runner on them. Simplified, it looks like this:

const result = await microvmSession<TestResult>(
  context,
  "patch-check",
  { imageIdentifier: imageArn, executionRoleArn: roleArn,
    timeout: { minutes: 30 } },
  async (vm, ctx) => {
    await vm.invoke(ctx, "prepare", { files: event.files },
      { path: "/prepare", timeout: { minutes: 2 } });
    return vm.invoke<TestResult>(ctx, "test", {},
      { path: "/test", timeout: { minutes: 10 } });
  }
);
Enter fullscreen mode Exit fullscreen mode

Under the hood, the SDK takes care of the tricky parts: an idempotent launch (a retry returns the same MicroVM, not a second one), heartbeats, retries and a terminate step that runs whether the job succeeded, failed or timed out.

The traps that keep a MicroVM running

This is where the preview gets interesting, because the mistakes are quiet ones:

  1. Default function timeout. Lambda's three-second default breaks every HTTP delivery, which means every session job. The docs recommend the retry window plus eleven seconds, so at least 71 seconds.
  2. Missing lambda:TerminateMicrovm. Everything appears to work, results arrive, but the MicroVM keeps running until the platform stops it, in the worst case for hours.
  3. Heartbeat timeout too tight. It starts before the launch, so it has to cover boot and possible throttling.
  4. Ending parallel work early. A branch that never sees its result never runs its terminate step either.

Short time limits are both your safety net and your biggest cost lever.

Isolation is not trust

One point I want to stress: the worker and the code under test share the same MicroVM. A malicious patch could, in principle, try to report "passed" on its own. The isolation protects your account and your other systems, not the meaning of the result. So a green check never replaces human review and the regular CI run. Also keep in mind that the MicroVM needs outbound internet access for the callback APIs, which means the tested code can reach out, too.

My verdict: a well-designed extension for a clear purpose, but explicitly not production-ready yet (version 0.1.0-alpha.0). If your team lets AI agents write code, building a prototype now is worth it.

What the full article covers

  • A complete, step-by-step patch check with TypeScript, the compute worker and an AWS CDK stack
  • How a job travels through the MicroVM, including the durable steps you will see in the execution history
  • The three IAM roles and why each gets exactly the permissions it has
  • Detailed fixes for every pitfall, plus notes on costs, networking and an FAQ

Read the full guide here: Durable Functions MicroVMs: test AI code safely

๐Ÿ“– This is the condensed version. The full article on sascha-ms.de goes deeper โ€“ with all code samples, diagrams and a short knowledge check.


๐Ÿ‘‰ Next step: Curious what your own Lambda functions cost? Try my Lambda cost calculator โ€“ it runs right in your browser.

๐Ÿ“ฌ Stay updated: New articles on serverless, AI and leading tech teams via RSS, browser push or the weekly newsletter (in German).

Originally published on sascha-ms.de. More articles on serverless, AI in everyday development and leading tech teams: sascha-ms.de/en

Top comments (0)