More of the agents we build now write code and run it: pandas to answer a question, a script to clean up a customer’s CSV. That code comes from a model, often reacting to text you don’t control, such as a web page or an email. If someone slipped instructions into that text, the code your agent runs is effectively theirs.
So when an agent runs code, what stops that code from reaching everything else on the machine? For most teams the answer is “a container”. Here is why that isn’t enough, and how gVisor and Kata Containers fix it without leaving Kubernetes.
A container is not a sandbox
A container feels isolated, but its walls are a trick the Linux kernel plays. The kernel is the core of the operating system, and every container on a machine talks to the same one, through hundreds of requests called system calls. One reachable kernel bug can be enough to break out. Then the attacker is on the machine with everyone else’s workloads and cloud credentials.
The usual lockdown helps: a filter on which requests are allowed (seccomp), dropping extra permissions, a read-only filesystem and a non-root user. None of it changes the fact that the kernel is shared. That is fine for code you wrote and reviewed. It is not fine for code a model wrote from text you don’t control. In Google’s Secure AI Framework terms, that’s rogue actions through an insecure integrated component, and a tool that runs code is the most powerful one an agent has.
Two ways to move the wall
Both are container runtimes, the piece that starts a container, so they plug into your existing tools. They differ in where they put the wall.
gVisor: a kernel in user space
gVisor, from Google, puts its own small kernel, called the Sentry, between your code and the real one. It answers the code's requests itself and passes only a small, filtered set to the real kernel. It ships as runsc and powers GKE Sandbox.
Costs: a few requests and system files aren't there, code that does a lot of file or network work is slower, and GPUs work through nvproxy with caveats.
Kata Containers: a small VM per pod
Kata Containers runs each pod (Kubernetes' unit of work) in a lightweight virtual machine with its own kernel. A kernel attack only lands in a throwaway VM. Reaching the real machine also means breaking the hypervisor, the layer that runs the VM.
Costs: slower start-up and more memory per pod, it needs hardware virtualisation (KVM), and there are more parts to patch.
| runc (default) | gVisor | Kata Containers | |
|---|---|---|---|
| Where the wall is | None, the kernel is shared | gVisor’s own kernel (Sentry) | The VM’s own kernel, behind the hypervisor |
| How much of the real kernel the code can reach | Almost all of it | A small, filtered set of requests | Only through the hypervisor |
| Start-up time and memory | Lowest | Low | Higher, a VM has to boot |
| Linux compatibility | Full | Most workloads, not all | Full |
| Code that does lots of file or network work | Fastest | Slowest | Close to native |
| Needs hardware virtualisation | No | No | Yes |
| GPUs | Yes | Via nvproxy, supported drivers only | Via device passthrough |
My PoC
To see what gVisor actually changes, without relying on a known kernel bug, I built a small proof of concept (PoC), KernelsAgent. An AI agent backed by a local model, qwen3:14b on Ollama, gets four plain-English requests. It writes the Python itself, without being told where it will run. Each probe is a few lines of code that pokes at the system and reports what it was allowed, seven probes across four tests. Every probe runs once under runc (Docker’s default) and once under gVisor, on Docker on WSL2 on my PC.
Tests 1 and 2 run in a locked-down container: no network, a read-only filesystem, a non-root user, no extra permissions and 256 MB of memory. Tests 3 and 4 use Docker’s default settings on purpose, to show what each runtime blocks on its own. A hardcoded version gave the same results. It’s one machine, not a benchmark.
Three things stood out:
gVisor makes up the machine
runc showed the code the real kernel, 6.18.54.1-microsoft-standard-WSL2, and the system's info files (/proc) gave away my Ryzen 7 9700X, 16 cores and 15 GB. gVisor answered 4.19.0-gvisor, an unknown CPU, 2 cores and 256 MB, the container's own limit. An attacker sizing up the machine aims at the wrong target.
It blocks without extra settings
On Docker's defaults, runc let the code open a raw socket, which lets it build any network packet it likes. gVisor refused. Both refused to attach a new filesystem (mount).
Missing beats forbidden
Both blocked io_uring, a fast file and network feature behind many recent kernel bugs. runc blocked it with a filter rule (EPERM, "not permitted") that one setting switches off. gVisor never built it (ENOSYS, "doesn't exist"), so there's nothing to switch on.
Two results look worse for gVisor. It let the code create a private network (unshare) and take control of a process it had started (ptrace). Both happen inside gVisor’s own kernel and never reach the real machine, while runc allowed the same ptrace on the real kernel. Whether unshare opens anything further inside gVisor is still on my list.
The model wrote different code on each run and never noticed a thing. From inside the sandbox it had no way to tell that the kernel version it was given was fake. Same request, different outcome, purely because of the runtime. No prompt or guardrail fixes that; the sandbox has to enforce it.
Try it yourself
Two files do the real work. sandbox.py runs whatever code it’s given in a locked-down container, and the runtime is the one line that changes. The agent script asks the model for code and hands it straight over.
# sandbox.py (trimmed): how the agent's code runs
cmd = ["docker", "run", "--rm", "-i",
"--network", "none", # no outbound traffic
"--memory", "256m", "--cpus", "1",
"--pids-limit", "128",
"--read-only", "--tmpfs", "/tmp:size=64m",
"--cap-drop", "ALL",
"--security-opt", "no-new-privileges",
"--user", "65534:65534"] # nobody, no credentials
if self.runtime: # "runsc" for gVisor
cmd += ["--runtime", self.runtime]
cmd += [self.image, "python", "-"] # code arrives on stdin
# syscall_agent_tests.py (trimmed): the agent writes the code
prompt = ("Write a short Python script that prints what "
"kernel/OS version the script is currently "
"running on. Use both platform.release() and "
"the contents of /proc/version.")
code = write_code(prompt) # qwen3:14b via Ollama
# the prompt and the code are logged before anything runs
r = DockerSandbox("gvisor").run(code)
print(r["stdout"]) # 4.19.0-gvisor
To run it:
# once, inside Ubuntu on WSL: installs gVisor and a second Docker engine
sudo bash setup-gvisor.sh
# then the same four tests, once per runtime
python syscall_agent_demo_runc.py
python syscall_agent_demo_gvisor.py
On Kubernetes the same switch is a RuntimeClass whose handler is runsc, plus runtimeClassName: gvisor on the pod.
What I’d run agent code on
Agent code: runsc
Anything an agent writes from text you don't control. In my run it hid the real machine, refused a raw socket on Docker's default settings and doesn't have io_uring at all. It's one flag.
A whole VM: Kata
When you need full Linux compatibility, a whole GPU or a VM wall between customers. It's not in my PoC yet.
Your own code: runc
Services you wrote and reviewed. Not everything needs a sandbox.
The runtime is one layer, not the whole defence. Keep the lockdown from sandbox.py as well. Put a human in the loop for anything that changes the outside world. Prompt filters will eventually miss something. When they do, the sandbox decides how much damage that miss can do.
The catch is speed. Every request detours through the Sentry, so in an earlier run, file-heavy work was about 7 times slower (3.7 s against 0.5 s), while start-up was the same.
I work on AI agent platforms in Singapore. If you run agent-written code in production, I’d like to hear how you sandbox it. Reach me by email or on LinkedIn.