Book a 30-min callBook a call

Sandboxing AI-generated code: containers, gVisor, microVMs and WebAssembly

How to sandbox code an AI agent writes and runs: the threat model, containers, seccomp, gVisor, Firecracker microVMs, Kata, WebAssembly and practical limits.

An agent box sending code into three nested boxes, with a crossed-out dashed path from the innermost box to a network globe.
Written by
BYD Tech
Published
Topic
Deep dives
Reading time
14 min read

Questions people ask

Is a Docker container enough to run AI-generated code?

For code you trust, a hardened container is a reasonable floor. For code a model wrote from untrusted input, a container alone leaves the host kernel as the only barrier, so add gVisor or use a microVM, and apply the usual controls: no network, no secrets, read-only root, resource limits and one sandbox per task.

What is the difference between gVisor and Firecracker?

gVisor is a user-space kernel: it intercepts a container’s system calls and handles them itself, with no virtual hardware. Firecracker is a virtual machine monitor on KVM: each microVM boots its own guest kernel behind hardware virtualization. gVisor needs no KVM and fits existing container tooling; Firecracker gives a VM boundary and needs KVM.

Can I sandbox Python with exec and restricted globals?

No. Python’s docs say audit hooks are not suitable for implementing a sandbox, and introspection lets code reach modules and builtins you tried to remove. Run untrusted Python in a separate process inside a container, gVisor or a microVM.

Should the sandbox have internet access?

Not by default. Most tasks need none, and network access is how stolen data leaves. When a task needs an API, route traffic through a proxy that allows only that domain and logs everything else.

Does WebAssembly work for agent-generated code?

It works when the code can be compiled to Wasm or run by an interpreter built for Wasm. A module can only use what its imports provide, and WASI grants file access per directory. It is a poor fit when the agent expects arbitrary native packages or binaries.

Building something like this?