deniz.in

Markets

Weather

Loading weather

· via dev.to (home feed)

AWS Lambda MicroVMs bring serverless Firecracker sandboxes for AI-generated code

AWS Lambda MicroVMs run untrusted, AI-generated code in isolated Firecracker VMs with their own HTTPS endpoints. A dev.to walkthrough shows how to build a sandbox and where the pitfalls lie.

AWS Lambda MicroVMs bring serverless Firecracker sandboxes for AI-generated code

Running code you did not write — an AI assistant's suggested fix, an agent that wants to test its own output, a beginner's first loop — has always been an awkward fit for serverless. According to a hands-on article on dev.to, AWS's Lambda MicroVMs are built for exactly that case, and x86 support added on November 11, 2026 makes them worth a closer look. The article walks through building a code sandbox in which every session gets its own isolated virtual machine, with no container cluster to operate.

How a MicroVM works

A MicroVM is a very lightweight virtual machine built on Firecracker, the same virtualization layer that sits underneath ordinary Lambda functions. The difference is control: you start the VM, it gets its own HTTPS endpoint, and it keeps its memory and disk state instead of being discarded after each run.

Startup is fast because of snapshots. When you create a MicroVM image, Lambda builds your Dockerfile, starts your application and waits for it to signal readiness through a /ready hook. It then freezes the complete memory and disk state, and every later MicroVM starts from that frozen image, so the application never boots again — a principle the author compares to Lambda's SnapStart.

An idle VM is suspended rather than destroyed: memory and disk are kept and you pay only for storing the state. The next request wakes it automatically, with Lambda briefly holding the request until the VM is ready. Lifetime is capped at eight hours including suspended time; VMs that stay suspended too long or exceed the maximum are terminated. Applications can also expose hooks such as /run, which Lambda calls once per new VM before any traffic arrives.

Functions versus MicroVMs

The dev.to piece draws a sharp line between the two. A Lambda function is event-driven, load-balanced by AWS, limited to 15 minutes per invocation, and its execution environment may be reused across invocations of the same function. A MicroVM has its own HTTPS endpoint with no load balancer, can run for up to eight hours, survives suspension with memory and disk intact, and gives each session or tenant a full operating system.

Billing follows that split: functions are charged per request and duration, while MicroVMs carry a baseline cost per second while running plus storage charges while suspended. The author's verdict is that functions remain the right tool for many short, similar invocations, and that MicroVMs are an addition to the toolbox rather than a replacement.

A sandbox in practice

The tutorial's example is a fictional learning platform where students write JavaScript exercises and an AI tutor proposes solutions. A Lambda function serves as the orchestrator behind an HTTP API: it creates a session, spins up a dedicated MicroVM, records the session-to-VM mapping in DynamoDB, forwards snippets and shuts sessions down. The orchestrator mints the authentication token for the VM endpoint itself and never exposes it to the browser.

Inside the VM, a small HTTP server receives snippets and executes each one in a separate Node.js process — no environment variables inherited, a fresh temporary working directory, a timeout and an output cap, with the process killed outright if it exceeds either. The author is explicit that these measures are conveniences; the actual security boundary is the MicroVM. The setup deploys with the Serverless Framework v4 and TypeScript, using the aws lambda-microvms CLI command in the us-east-1 region.

The pitfalls

Two caveats stand out. First, outbound internet access is open by default, so for untrusted code you have to close it deliberately — something the article calls the model's biggest pitfall.

Second, because every VM starts from the same snapshot, anything held in memory at build time is identical across VMs. A session ID, counter or random value created at startup would be the same in every instance. That is precisely what the /run hook is for: per-VM values should be assigned there before traffic arrives, and AWS recommends a cryptographically secure random number generator for anything that must be unique.

When to use them

According to the article, AWS lists sandboxes for AI code, interactive development environments, notebooks, security scans and multi-tenant CI/CD runners among the intended use cases. The author narrows this to three questions: are you running code you do not control; does the session need state for minutes or hours, such as installed packages, open database connections or an ongoing agent conversation; and do you need operating system capabilities a function cannot offer? Three noes means staying with functions — a plain REST API only becomes costlier and more complicated on MicroVMs.

Why it matters

AI coding assistants and autonomous agents increasingly need somewhere safe to execute the code they produce, and the usual options are unappealing: running generated code inside your own function runtime is risky, while maintaining a container cluster purely for sandboxes drags you back into server operations. Lambda MicroVMs package a per-session, Firecracker-isolated virtual machine into a serverless model — billed while running, cheap while suspended, with no fleet to manage — turning strong isolation into a composable building block. The details still matter: default-open networking and shared snapshot state mean security is not automatic, and the per-second baseline means teams should model costs against their session patterns before committing. For platforms hosting third-party or machine-written code, this is one of the first serverless primitives aimed directly at them.

  • #aws
  • #lambda
  • #serverless
  • #cloud
  • #sandboxing

Related posts