← Blog

WebAssembly or a microVM for agent-written code? A comparison from the projects' own docs

WebAssembly runtimes and microVMs both promise to run untrusted code safely, in very different ways. What each boundary is, what code each can run, and which fits the code AI agents actually write.

“Run it in WebAssembly” and “run it in a microVM” are both serious answers to the question of where untrusted code should execute. They come from different traditions, browsers on one side and cloud virtualization on the other, and they make different trade-offs. For code written by AI agents, the deciding factor is usually not which boundary is stronger in the abstract, but what the agent’s code needs to do.

This comparison sticks to what the projects say about themselves. For WebAssembly we use Wasmtime’s security documentation; for microVMs, the Firecracker project README. We have a stake in this, since Sandscale runs on Firecracker, so we have tried to be fair, and to say where WebAssembly is the better pick.

Two different boundaries

WebAssembly: a language-level sandbox

A WebAssembly module is compiled code for a virtual instruction set, executed by a runtime inside your process. Wasmtime’s docs list the properties that make it a sandbox:

  • The call stack is not accessible to the program, so classic stack-smashing attacks on return addresses do not apply.
  • Pointers become offsets into the module’s linear memory, and every access is bounds-checked.
  • Every branch and call goes to a known, type-checked destination.
  • There is no raw access to system calls or other I/O. In the docs’ words, the only thing an instance can do is what is available through interfaces it has been explicitly linked with.

Files come through WASI, which Wasmtime describes as a capability-based model where applications can only access the files and directories they have been given. On top of the spec, Wasmtime adds defense in depth: guard regions around linear memory, guard pages on native stacks, zeroing memory after an instance finishes, and some Spectre mitigations.

The boundary is the runtime itself: its compiler, its checks and the host functions you link in.

A microVM: a hardware-virtualized machine

Firecracker describes itself as a virtual machine monitor that uses Linux KVM to create and run microVMs, which combine the isolation properties of hardware virtualization with the flexibility of containers. Each microVM boots its own guest kernel. Firecracker’s minimalist design excludes unnecessary devices and guest-facing functionality to reduce the attack surface.

Inside the guest, programs see an ordinary Linux machine: processes, a filesystem, a shell, system calls. The boundary is the hardware virtualization layer, KVM, and the small device model the VMM exposes. Our post on Firecracker’s defense in depth covers the layers around it, such as seccomp filters and the jailer.

Side by side

WebAssembly runtime microVM
Boundary Runtime checks plus the host functions you expose Hardware virtualization plus a minimal device model
What runs Code compiled to WebAssembly, or interpreters compiled to it Any Linux program for the guest’s architecture
System calls None directly; only imported host functions A full guest kernel
Files Only directories granted through WASI A guest filesystem you provision
Network Only what host functions provide Whatever the network setup outside the VM allows
Where it runs Inside your process, or a process you manage A separate VM per workload
A bug in the boundary means Code may reach your host process Code may reach the host through the VMM or KVM

Both columns have a “bug in the boundary” row because both boundaries are software that has had bugs. Neither is a guarantee. They fail in different places, and how you layer around them matters as much as the choice itself.

What agent code actually does

The comparison above is abstract. Here is what coding agents typically do in a run:

  • Run python3 script.py or node script.js, often using packages with native extensions.
  • Install dependencies with pip or npm.
  • Run a test suite, a compiler or a linter.
  • Use git, grep, sed and other command-line tools.
  • Spawn subprocesses, use threads, and read and write files across a project tree.

A microVM runs all of that unchanged, because it is a Linux machine. A WebAssembly runtime can run some of it: interpreters such as CPython have WebAssembly builds, and pure-language code often works. But anything that expects a POSIX environment, such as spawning processes, calling native libraries, or using tools that were never compiled to WebAssembly, needs either a WebAssembly build of each piece or host functions you write and secure yourself. Every host function you add widens the boundary you are trusting.

When WebAssembly is the better choice

  • The code is small and its language is fixed. Plugins, user-defined functions, formulas and data transforms where you control the toolchain.
  • You want the sandbox inside your process. No separate machine, no network hop, and fine-grained control over exactly which host functions exist.
  • Capabilities are the point. If the code should be able to do exactly three things, defining those three host functions is cleaner than taking a full Linux environment away piece by piece.
  • You run on the edge or in the browser, where WebAssembly is what is available.

When a microVM is the better choice

  • The code is arbitrary. Agents write whatever the task needs, in whatever language, with whatever packages.
  • The workload needs a real OS: processes, a shell, package managers, compilers, test runners.
  • You want the boundary outside your process. A crash or a compromise inside the VM does not land in your application’s memory.
  • You need a whole project tree, with tools that assume a normal filesystem.

Layering, either way

Whichever you choose, the habits that matter are the same:

  • Give the sandbox no secrets it does not need. Neither boundary hides from code what you put inside.
  • Deny network by default and allow it per task. See egress allowlist design.
  • Limit time, memory and output.
  • Treat output as untrusted. Wasmtime’s docs make a nice point here: untrusted code that prints to a terminal can emit escape sequences with side effects, so Wasmtime filters them by default. The same applies to output you show from any sandbox.

Where Sandscale fits

Sandscale runs each agent run in its own Firecracker microVM, because coding agents mostly produce the second kind of workload: arbitrary programs that expect a Linux machine. If your agent only evaluates small expressions or runs plugins in one language you control, a WebAssembly runtime in your own process may be all you need, and our post on why node:vm and exec are not sandboxes explains why that runtime should be a real WebAssembly engine and not a language trick.

Run your agents in a box of their own

Each sandbox is a Firecracker microVM. Free includes 100 awake vCPU-hours a month.

Start free

Keep reading