Running AI-Generated Code: Containers, gVisor or MicroVMs?

An agent that writes code also has to run it. We compare the three common isolation models, say where microVMs fall short, and list the risks that isolation alone does not remove.
The problem with letting an agent run code
The most useful thing an AI agent can do is write a script and run it: analyse a spreadsheet, convert a file, test a fix. It is also the most dangerous. The code was written by a model that may have read untrusted text, such as a web page or an uploaded document, so you cannot assume it is code you would have written or reviewed yourself.
The question is therefore not whether to isolate that code, but where to draw the boundary between it and everything else on the server.
Three isolation models
Ordinary Linux containers separate processes with kernel namespaces and permission controls, but every container on a machine shares the host's kernel. A flaw in the kernel is a flaw in every container's wall. That is acceptable for code you wrote and reviewed. It is a thinner defence for arbitrary code from users or agents.
gVisor adds an application kernel written in user space. The program's system calls are handled by that layer instead of going straight to the host kernel, which shrinks the exposed surface while keeping container tooling.
A microVM gives each workload its own guest kernel and uses hardware virtualisation (KVM on Linux) as the boundary to the host. Firecracker is the best-known example, and the same idea is available in lighter embeddable runtimes. The code inside can do whatever it likes to its own kernel and still be on the wrong side of a hardware boundary.
Are microVMs up to the mark?
For running untrusted, model-written code, we think yes. A separate kernel per workload removes the shared-kernel weakness that makes container escapes serious, and it makes an ephemeral, throw-away environment natural: when the task ends, the whole machine is destroyed with anything the code left behind.
The same properties explain the strengths of the approach in practice. Nothing a run installs or modifies survives it. One user's code never touches another user's machine. And a compromise of the guest still has to cross a hypervisor to matter.
Where microVMs fall short
They need hardware virtualisation on the host, and some cloud instances do not expose it, which limits where you can run them. Every VM costs memory and boot time, so you must budget capacity and cap concurrency rather than start one per request. Packaging is another cost: the guest image needs building, publishing and updating. Some tools that assume a full Linux machine with its own container engine need extra testing before they work inside the guest.
None of these are fatal, but they are real operational work, and they are the honest reason gVisor and containers remain reasonable choices for lower-risk workloads.
What isolation does not fix
This is the part people skip. Neither gVisor nor a microVM denies outbound network access by default, and neither enforces your business rules. Code inside the sandbox can use whatever files and connections you gave it. If a prompt-injected script can read a customer file and reach the internet, a perfect boundary will not stop it sending the file out.
So isolation has to be paired with the rest of the design: keep secrets and credentials out of the sandbox, share only the folder the task needs, limit run time and output size, control or monitor network egress, and treat everything that comes back out as untrusted until it is validated.
How Breifex AI runs code
Every chat that needs code gets its own microVM, with its own Linux kernel, running through the microsandbox runtime on KVM. The only host folder it shares is that message's workspace. Execution is fail-closed: if no healthy sandbox is available, code does not run on the host instead, and the tools that need it are not offered. A VM is destroyed when its turn ends, when it has been idle for a minute, or when it reaches a maximum age, and a destroyed VM is never reused by anyone else. Results are validated and read back in a way that refuses swapped symbolic links.
Our own caveat: the throw-away VM is allowed internet access and package installs so agents can do useful work, which means network egress is a risk we manage with isolation and limits rather than remove. We would rather say that plainly than claim the sandbox makes a prompt-injected agent harmless.

