AWS Builder Center
Your AI Agent Runs Untrusted Code. Sandbox It the Way AWS Sandboxes Lambda — on an EC2 Bare-Metal Instance

Your AI Agent Runs Untrusted Code. Sandbox It the Way AWS Sandboxes Lambda — on an EC2 Bare-Metal Instance

kindling is an open source runtime that gives every AI tool (MCP server) its own Firecracker microVM — frozen on disk at zero cost, awake in milliseconds. Here's the problem it solves, how it works, the engineering behind it (shared Chromium, copy-on-write memory, per-session secrets), and how to run it on an EC2 bare-metal instance, x86 or Graviton.

Software Engineer - AI Student
AI assistants run third-party tools — MCP servers — as local processes with access to your files, your secrets, and your network.  kindling  is an open source runtime that puts each tool in its own Firecracker microVM (the same technology AWS uses to isolate Lambda), freezes it on disk at zero cost when idle, and wakes it in milliseconds when a request arrives. This article covers the problem it solves, how it works under the hood — golden snapshots, copy-on-write memory, a single Chromium shared across sessions, secrets that never touch the disk — and how to deploy it on AWS on an EC2 bare-metal instance, x86 or Graviton.

The problem: strangers' code with the keys to your house

An MCP server is almost always unaudited third-party code that you install with  npx -y whatever . It runs as one of your processes: it sees your files, your environment variables, your network. The actual security boundary is your trust in the package author — and in every one of their transitive dependencies.

A container improves things, but it shares the host kernel: a single kernel bug stands between the tool and your data. And there is a second, more mundane problem: the cost of keeping tools switched on. A typical agent uses dozens of tools, each one a Node process weighing hundreds of MB, and they sit idle ~90% of the time waiting for the LLM.
I wanted both things at once:
  1. Hardware-level isolation: every tool with its own guest kernel. The design assumes the guest is hostile — there is no telling which MCP server will end up being hosted.
  1. Zero cost at rest: dozens of tools "installed" that burn neither CPU nor RAM while they sleep.
That combination is exactly what Firecracker makes possible — and kindling packages it behind a docker-like interface.

What kindling is

A single Go binary,  kling , that is both CLI and daemon. It manages Firecracker microVMs with docker-like ergonomics, and on top of that runs an MCP gateway that turns any open source MCP server — whether it speaks stdio or Streamable HTTP — into an on-demand service:

  •  kling run / freeze / thaw  — the  warm  state is the key piece: the microVM frozen on disk burns no CPU and no RAM, and wakes in milliseconds. It is what separates kindling from a container runtime.
  • Golden snapshots — freeze a template once and instantiate N copies that share its memory.
  •  kling add <mcp-server>  — imports an MCP server from npm, bakes it into an image, and publishes it on the gateway.  kling migrate  moves an already-configured MCP server without rewriting your agent's skills: it keeps the tool names and the endpoint per service.
  • A gateway with sessions and replicas — every MCP client gets its own session; if two agents request the same tool at once, the gateway spins up replicas from the same snapshot (scale-out).
  • stdio→HTTP bridge — classic stdio MCP servers get exposed as Streamable HTTP without touching their code.
  • Self-configuration — on import, kindling inspects the package's dependency tree and infers what it needs: an HTTP client → opens internet egress; Playwright/Puppeteer → bakes Chromium into the image; a native module → warns you. No flags.
  • Operations: per-token/tenant quotas,  kling top  (real memory, PSS), Prometheus  /metrics , an event log,  kling squeeze  (memory balloon).

How it solves the problem: the architecture


The lifecycle of a tool is pure serverless — on your own server:
  1. It is imported once and frozen as a golden snapshot ( warm  state: 0 CPU, 0 RAM, a few MB on disk).
  1. A request arrives → the gateway thaws the microVM in milliseconds, routes the session, and freezes it again when it goes idle.
  1. Parallel demand → replicas from the same snapshot, each in its own microVM.
The economics are Lambda's — sleeping costs nothing; you pay (in RAM) only for what is awake — without your data or your tools ever leaving your machine.

The fine engineering (where it gets interesting)

One Chromium, N isolated sessions

Browser tools are the worst case for cost: every Chromium instance is hundreds of MB. The obvious approach — one browser per session — does not scale. What kindling does instead: when it detects that an MCP server needs a browser, it bakes Chromium into the image, and the bridge launches a single instance with CDP (lazily: on the first session, not at boot). Each MCP session connects to that Chromium with its own isolated context, tied to its  Mcp-Session-Id : separate cookies, pages, and state — one heavy process. Verified with concurrent sessions browsing different URLs without crossing over.

Copy-on-write memory: sleeping (almost) for free


Co-resident replicas of a tool map the golden snapshot copy-on-write: ~30 MiB of private memory per replica instead of 192 MiB. In the lab: 100+ microVMs per host and roughly 40× less RAM than the equivalent resident processes.

Hunting the cold start: 16 s → 2.5 s



Cold start in my arm64 lab began at ~16 s. The first measurement dismantled the obvious suspect: restoring the snapshot takes ~140 ms and thawing ~4 ms. The cost was Node's cold start — and it was not compute, but the storm of file accesses while loading hundreds of modules, which the lab's nested KVM amplifies ~25–60×. Two levers brought it down 6.4×: giving the microVM its real CPU budget during boot, and bundling the server into a single file with esbuild (hundreds of accesses → one). The architecture lesson: measure before you optimize — the bottleneck was not where it seemed to be.

Security: the guest is hostile

kindling's threat model starts from the fact that you don't know which MCP server will end up hosted. The barriers, from the inside out:
  • A hardware boundary: every tool runs behind KVM with its own guest kernel — the same boundary AWS Lambda uses between tenants. Firecracker additionally runs under the jailer (chroot, cgroups, unprivileged user).
  • Per-session secrets via MMDS: they are injected into the live microVM when the session opens; the snapshot on disk never contains secrets.
  • Fail-closed egress: three network modes; the allowlist mode only permits the declared domains (DNS→ipset). A compromised tool cannot exfiltrate to wherever it likes.
  • The daemon never listens on a TCP port: controlling microVMs is equivalent to root, so control goes over a Unix socket — and remotely over SSH ( kling dial-stdio , like  docker context ). It does not repeat the mistake that cost Docker a decade of compromised servers.
  • Integrity: images verified by sha256.

Stability: two labs, real tests


This is not a demo prototype. The same binary has been running for weeks in two labs:
  • x86 (Proxmox): 9 MCP services resident in daily use, 22 ms thaws.
  • arm64 (Mac M4, Linux VM): the harshest environment tried — KVM nested twice — and still 2.5 s cold starts and ~4 ms thaws.
The suite runs under  go test -race ; the hot paths (freeze/thaw, replicas, sessions, recycling) have concurrency tests, and findings from the labs went back into the code as fixes (e.g., a thaw that didn't reapply the CPU limit, or the gateway's session recycling). Parallelism is characterized with numbers too: for bursts of cold sessions, the http-proxy mode serves 12 concurrent sessions from a single instance.
The cross-lab evidence supports the next section: bundling barely helps on x86 but gives 2.9× on nested arm — the cold-start tax is the nesting, not the architecture. So let's remove the nesting.

Taking it to AWS: bare metal, x86 or Graviton

Firecracker needs KVM ( /dev/kvm ). On a regular EC2 instance your OS already runs inside the Nitro hypervisor and there is no nested virtualization: Firecracker won't start. The way in is a  .metal  instance: the entire physical server, with the CPU's virtualization extensions exposed. Lambda is Firecracker running on AWS bare metal you never see; if you want your own, you rent the metal directly.
Both families work — kindling is the same binary on either:
  • Graviton (arm64):  a1.metal  (16 vCPU, ~$0.41/h) is the cheap way in;  c7g.metal  is current-gen. (Verify pricing/availability in your region.)
  • x86:  c6i.metal ,  m7i.metal … big machines (48–128 vCPU, ~$4–5/h) if you already live on x86 or need that capacity.
Setup in 5 steps:
  1. Launch the  .metal  instance (Ubuntu arm64/x86 or AL2023). Confirm KVM:  test -e /dev/kvm && echo ok .
  1.  curl -fsSL .../install.sh | sh 
  1.  kling up  (kernel, base image, networking).
  1.  kling add <mcp-server> -bundle 
  1. Point your MCP client at the gateway.
When NOT to use this: if you want zero operations and pay-per-use, managed hosting (e.g. Bedrock AgentCore Runtime, which also isolates with per-session microVMs) is the default path — and a good one. This setup is the other end of the spectrum: flat, predictable cost for dozens of warm tools, full control, on-prem/air-gapped from day one, and the guarantee that your tools and your data never leave your server.


kindling is open source:  github.com/juan52878911/kindling . Real  .metal  benchmarks will land in an update to this article — if you run them before I do, tell me about it.


Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article