This post is part of the Kubezilla sandboxing series: Part 1: The two layers · Part 2: The cluster layer · Part 3: The runtime layer and Docker Sandboxes.
AI agents now write code, run shell commands, install packages and call APIs on their own. That is useful, and it is also risky. One bad prompt, one poisoned dependency or one confused tool call can turn an agent into the most privileged process in your environment.
Most teams answer this with “put it in a sandbox.” But a sandbox is not one thing. When you run agent workloads on Kubernetes, or on a laptop with Docker Sandboxes (sbx), there are really two layers doing the work:
- The cluster layer: what the workload is allowed to reach. Namespaces, RBAC, service accounts, NetworkPolicy, Pod Security, quotas and admission policies.
- The runtime layer: what happens if the code inside escapes its process. This is the kernel boundary: plain containers, gVisor, Kata Containers, Firecracker style microVMs, and Docker Sandboxes.
If you only have one of these, you have a gap. This series walks through both.
Why one layer is not enough
Think about a normal container on a Kubernetes node. It shares the host Linux kernel with every other pod on that node. The cluster layer can stop it from calling the Kubernetes API or reaching your database. But if the agent runs code that exploits a kernel bug, the cluster rules do not help. The code is now on the node.
Now flip it. Imagine a strong microVM with its own kernel, but running with a cluster-admin service account token mounted and open egress to the internet. The kernel boundary is solid, yet the agent can still delete deployments or send your secrets to any host it likes. Nothing escaped. It just used the access you gave it.
So the two layers answer two different questions:
| Question | Layer | Typical controls |
|---|---|---|
| What can this workload talk to and change? | Cluster layer | RBAC, ServiceAccounts, NetworkPolicy, ResourceQuota, Pod Security Admission, admission policies |
| If the code is hostile, can it reach the host? | Runtime layer | RuntimeClass with gVisor or Kata, microVMs, Docker Sandboxes (sbx) |
| Who sees what happened? | Both | Audit logs, network flow logs, sbx policy log |
The cluster layer in one minute
The cluster layer is about blast radius. It treats every agent as a tenant you do not fully trust. A good baseline looks like this:
- One namespace per agent, team or session, so limits and policies have a clear home.
- A dedicated ServiceAccount with no token mounted unless the agent truly needs the Kubernetes API.
- A default deny NetworkPolicy for ingress and egress, with only the endpoints the agent needs opened up.
- Pod Security Admission set to
restricted: no root, no privilege escalation, no host paths. - ResourceQuota and LimitRange so a runaway agent cannot eat the node.
- A separate node pool for sandboxed workloads, using taints and tolerations.
We go deep on each of these, with YAML you can copy, in Part 2: The cluster layer.
The runtime layer in one minute
The runtime layer is about the kernel boundary. Standard containers (runc) are process isolation. They are fast, but they share the host kernel. For code written by an LLM, that is often not enough. Your options get stronger as you go down the list:
- runc: normal containers. Namespaces and cgroups on a shared kernel.
- gVisor (runsc): a user space kernel that sits between the app and the host kernel and handles system calls itself.
- Kata Containers: each pod runs inside a lightweight VM with its own kernel.
- microVMs (Firecracker and similar): very small VMs that start in a fraction of a second.
- Docker Sandboxes (sbx): each agent runs in its own microVM with a separate kernel, and all outbound traffic goes through a host side proxy that enforces policy.
In Kubernetes you pick a runtime per pod with runtimeClassName. The Agent Sandbox project from Kubernetes SIG Apps builds on this. It adds Sandbox, SandboxTemplate, SandboxClaim and SandboxWarmPool resources and works with gVisor or Kata underneath.
We compare these runtimes and show how Docker Sandboxes fits in, in Part 3: The runtime layer and Docker Sandboxes.
Where Docker Sandboxes (sbx) fits
Docker Sandboxes is interesting because it packs both layers into one tool. The microVM gives you the runtime layer. The network proxy, deny by default egress, workspace modes and host side credential injection give you a small, local version of the cluster layer.
That makes it a good mental model. When you move an agent from a laptop to a cluster, you want the same two things: a strong kernel boundary, and tight rules about what the agent can reach. The tools change. The two layers stay the same.
A simple checklist
- Can the agent reach the Kubernetes API? If yes, is it the smallest RBAC role that works?
- Is egress denied by default, with an allow list?
- Does the pod run as non-root under the
restrictedPod Security level? - Does the pod use a stronger runtime than runc (gVisor, Kata or a microVM)?
- Are secrets injected from outside the sandbox instead of sitting in env vars or files?
- Do you log network decisions and API calls so you can see what the agent did?
If you answer “no” to the runtime questions, you have a cluster layer only setup. If you answer “no” to the access questions, you have a runtime layer only setup. You want both.
