Runtime

Can you run LLM code on AWS Lambda?

Yes, for short stateless runs: a Lambda function stops at 15 minutes. AWS's newer Lambda MicroVMs add suspend and 8-hour sessions.

Runtime runs 1,000 one-minute jobs of 2 vCPUs and 4 GiB for $0.64, against $4.00 on a 4,096 MB Lambda function and $4.20 on a Lambda MicroVM, because it bills the CPU the code uses rather than the memory or cores it holds for the whole minute. AWS rates for US East (N. Virginia), checked 25 September 2026; Runtime's are in pricing.

What a Lambda function allows

AWS says Lambda "is designed for short-lived compute tasks that do not retain or rely upon state between invocations." The limits that matter for code a model wrote:

Limit Lambda function, as AWS documents it
Longest run 900 seconds (15 minutes) per invocation
Memory 128 MB to 10,240 MB
CPU In proportion to memory; "at 1,769 MB, a function has the equivalent of one vCPU"
Writable disk /tmp, 512 MB to 10,240 MB
Code package 50 MB zipped, 250 MB unzipped; 10 GB as a container image
Request and response 6 MB each, synchronous
Concurrency 1,000 by default, raised on request
Price $0.0000166667 per GB-second on x86, $0.20 per million requests
Free tier 1 million requests and 400,000 GB-seconds a month

Where a function gets awkward for model code

  • Leftovers between invocations. Lambda reuses a frozen execution environment: "the directory content remains" in /tmp, objects outside the handler stay initialized, and background processes that did not finish "resume if Lambda reuses the execution environment". Code from one request can meet what an earlier one left behind in the same function.
  • No shell to talk to. A function takes an event and returns a response. Installing a package, running a test suite, then reading a file is one invocation you script yourself, or several that may land on different environments.
  • 15 minutes, then gone. A build, a long test run or an agent loop that needs longer has to be cut up and carry its state somewhere else.
  • Memory buys CPU. Two vCPUs mean about 3,538 MB, and the whole allocation is billed for every millisecond, idle or busy.

Lambda MicroVMs

AWS announced Lambda MicroVMs on 22 June 2026 as "a new serverless compute primitive that provides VM-level isolation, near-instant launch and resume speeds, and state preservation for executing user or AI-generated code."

  • Isolation. Firecracker virtualization; each MicroVM runs Amazon Linux 2023.
  • Images. A Dockerfile on a Lambda-managed base image, uploaded as a zip to S3, built into a snapshot of the initialized environment.
  • Access. Clients reach each MicroVM through its own HTTPS endpoint; outbound goes to the public internet or your VPC.
  • Suspend. An idle MicroVM suspends "preserving memory and disk state" and resumes when traffic returns, for up to 8 hours.
  • Limits. 8 hours of execution at most; ARM64 (Graviton); default size 2 GB and 1 vCPU, CPU at a 2:1 memory-to-CPU ratio, bursting to 4 times the baseline. Five regions at launch: three in the US, Ireland and Tokyo.
  • Price. $0.0000276944 per vCPU-second and $0.0000036667 per GB-second of baseline while running, $0.08 per GB-month while suspended.

What each costs

The same job everywhere: 1,000 runs, each 60 seconds long and using 20 CPU-seconds, on about 2 vCPUs and 4 GB. Request charges are included; free tiers are left out.

Service Working 1,000 runs
Runtime, 2 vCPU and 4 GiB 1,000 × 20 s / 3,600 × $0.025 + 1,000 × 60 s / 3,600 × 4 × $0.0075 $0.64
Lambda function, 4,096 MB, x86 1,000 × 60 s × 4 GB × $0.0000166667 + 1,000 × $0.20 / 1,000,000 $4.00
Lambda MicroVM, 2 vCPU and 4 GB 1,000 × 60 s × (2 × $0.0000276944 + 4 × $0.0000036667) $4.20

With both CPUs busy for all 60 seconds Runtime comes to $1.33; the Lambda figures do not change, since both bill the allocation. Waiting between requests, the Runtime sandbox costs $0.03125 an hour, and a running MicroVM at 2 vCPU and 4 GB costs 3,600 × (2 × $0.0000276944 + 4 × $0.0000036667) = $0.2522 an hour at baseline. Lambda's free tier of 400,000 GB-seconds a month covers the first 1,666 of these runs on a function.

The Runtime equivalent

A sandbox is a whole Linux machine you drive command by command, with no 15-minute ceiling: a command may run for up to 24 hours, and the lease is extended as often as you need.

TypeScriptimport { Sandbox } from "withruntime";const code = "import time\ntime.sleep(1)\nprint('done')"; // what the model wroteawait using sbx = await Sandbox.create({ timeoutSeconds: 3600, onLeaseEnd: "stop" });await sbx.files.write("/workspace/job.py", code);const run = await sbx.exec(["python3", "job.py"], { timeoutMs: 1_800_000 }); // 30 minutes allowedconsole.log(run.exitCode, run.timedOut, run.stdout);
Pythonfrom withruntime import Sandboxcode = "import time\ntime.sleep(1)\nprint('done')"  # what the model wrotewith Sandbox.create(timeout_seconds=3600, on_lease_end="stop") as sbx:    sbx.files.write("/workspace/job.py", code)    run = sbx.exec(["python3", "job.py"], timeout_ms=1_800_000)  # 30 minutes allowed    print(run.exit_code, run.timed_out, run.stdout)

Each sandbox is a fresh Firecracker microVM with its own kernel, so nothing carries over from another request. A pause keeps its files, memory and processes for 1 to 365 days, and root inside cannot change its network rules, CPU, memory or cost (security).

Which one fits

  • A Lambda function for short, trusted steps around the model: parsing, calling an API, writing a result, all inside 15 minutes and your AWS account.
  • Lambda MicroVMs when the sandbox must live in your AWS account and a session of up to 8 hours on Graviton is enough.
  • Runtime for model-written code that installs packages, runs commands one after another, pauses for days, forks, or runs x86 tools, billed on the CPU it uses. Sandbox.identityToken trades a sandbox's OIDC token for AWS credentials, so code in it can still reach your account without a stored key (identity tokens).

New accounts get 50 free sandbox hours, no card.

More: run untrusted LLM code, what is a cold start?, agent evals and SWE-bench, self-hosted vs managed sandbox.

Sources

Checked 25 September 2026.

Facts on this page were checked on 25 September 2026.