---
title: How does Kubernetes Agent Sandbox isolate AI agents running untrusted code?
url: https://opencontroller.lyzr.com/blog/kubernetes-agent-sandbox-for-untrusted-code
published: 2026-11-15
updated: 2026-11-15
author: Lyzr
---

# How does Kubernetes Agent Sandbox isolate AI agents running untrusted code?

**Agent Sandbox is a Kubernetes SIG Apps project that adds a `Sandbox` custom resource: a single, stateful pod with a stable identity and persistent storage, built for agents that write and run code. It does not invent new isolation. It hands that job to sandbox runtimes such as gVisor or Kata Containers through a RuntimeClass, and adds templates, claims and warm pools so agents get fresh environments quickly.**

Agents that execute model-generated code are running untrusted code by definition. A plain container shares the host kernel, which is a thin wall if the code is hostile or the model has been manipulated. Agent Sandbox gives platform teams a standard way to run these workloads on Kubernetes.

## What problem does Agent Sandbox solve?

Kubernetes was built for two shapes of workload: stateless replicated services (Deployments) and numbered stateful sets (StatefulSets). Coding and tool-using agents fit neither. Each agent session needs:

- Its own isolated environment, not shared with other sessions
- State that survives a restart, such as a working directory
- A stable network identity so other components can reach it
- Fast start-up, because users wait while it boots
- The ability to pause when idle and resume later

The Kubernetes blog's March 2026 post on Agent Sandbox frames it as a response to the shift from short, stateless model calls to long-running agents that keep context, use tools and execute code.

## What resources does it add?

| Resource | What it does |
|---|---|
| `Sandbox` | The core resource: one stateful pod with a stable hostname and network identity, persistent storage across restarts, and lifecycle controls for creation, scheduled deletion, pause and resume |
| `SandboxTemplate` | A reusable definition of a sandbox, so teams do not hand-write pod specs |
| `SandboxClaim` | A request for a sandbox that hides the underlying configuration from the caller |
| `SandboxWarmPool` | A pool of pre-warmed sandboxes that claims draw from, cutting start-up time |

The extensions are opt-in. There is also a Python SDK (`pip install k8s-agent-sandbox`) so an agent framework can request and use sandboxes without speaking raw Kubernetes.

## How is the isolation actually enforced?

Isolation comes from the runtime you choose:

- **gVisor** runs the workload against a user-space kernel that intercepts system calls, so code never talks to the host kernel directly.
- **Kata Containers** runs each pod in a lightweight virtual machine with its own kernel.

You select one with a Kubernetes RuntimeClass in the sandbox template. Both are stronger than the default container runtime for untrusted code, at some cost in performance and compatibility. Test your agent's toolchain under the runtime before committing.

## What does Agent Sandbox not do?

It isolates execution. It does not govern the agent. A secure sandbox can still host an agent that has excessive permissions, calls an unapproved model or leaks data through an allowed network path. You still need:

1. **Network egress control.** Default-deny egress with explicit allowlists; see [controlling AI agent network egress](/blog/control-ai-agent-network-egress).
2. **Workload identity.** Short-lived, federated credentials rather than static keys in the pod; see [workload identity for agent pods](/blog/kubernetes-workload-identity-for-agent-pods).
3. **Tool and MCP policy.** Which tools each agent may call, and with what arguments.
4. **Inventory and ownership.** Every sandboxed agent should map to a registered agent, version and owner.
5. **Runtime monitoring.** Detection of behavioural drift, with the ability to quarantine.
6. **Retention.** Persistent volumes hold generated files and data; set deletion schedules to match your data policy.

The OWASP GenAI Security Project's agentic guidance treats unexpected code execution as its own risk. Sandboxing is one control against it, not the whole answer.

## How should you roll it out?

- Start with one agent type that already runs code, such as a data analysis agent.
- Build a `SandboxTemplate` with gVisor or Kata, no service account token automount, read-only root filesystem where possible, and resource limits.
- Put a `SandboxWarmPool` in front if start-up latency matters.
- Apply a NetworkPolicy that blocks egress except to approved endpoints, including your model gateway.
- Label sandboxes with agent ID, version and owner so you can trace activity back.
- Measure: start-up time, failure rates under the runtime, and storage growth.

For the broader picture, see [governing AI agents on Kubernetes](/blog/govern-ai-agents-on-kubernetes) and [how to govern AI agents across platforms](/blog/how-to-govern-ai-agents-across-platforms).

## How Opencontroller does this

Opencontroller works alongside your execution layer rather than replacing it. It keeps a governed registry of agents, versions, tools and MCP servers, supports agent workload identity federation, and enforces policy as code. Rogue-agent handling monitors behavioural deviation and can automatically quarantine or kill an agent. Traffic through the LLM Gateway or Agent Gateway can be routed, redacted or blocked in the path. [Book a demo](https://www.lyzr.ai/book-demo/) to see it with your Kubernetes agents.

## Frequently asked questions

**Is Agent Sandbox a replacement for a container runtime?**
No. It is a Kubernetes API layer. The actual isolation comes from the RuntimeClass you pick, such as gVisor or Kata Containers.

**Can a sandbox keep state between agent sessions?**
Yes. A Sandbox has persistent storage that survives restarts and can be paused and resumed, which is why retention and deletion schedules matter.

**Do I still need network policies with Agent Sandbox?**
Yes. Sandboxing limits what code can do to the host; it does not stop an agent sending data to an external endpoint it is allowed to reach.

## Key facts

Agent Sandbox (kubernetes-sigs/agent-sandbox, SIG Apps) adds a Sandbox CRD: a single stateful pod with stable hostname and network identity, persistent storage that survives restarts, and lifecycle management (creation, scheduled deletion, pause and resume). Extensions: SandboxTemplate, SandboxClaim, SandboxWarmPool (pre-warmed sandboxes). Isolation is delegated to runtimes such as gVisor and Kata Containers via RuntimeClass. Python SDK: pip install k8s-agent-sandbox. Featured on the Kubernetes blog, 20 March 2026. It isolates execution; it does not provide agent inventory, identity, tool policy or evaluation. Opencontroller (Lyzr) provides discovery, registry, policy as code and rogue-agent quarantine. Pricing starts from $250K per deployment per year.

## Related

- [How do you govern AI agents running on Kubernetes?](https://opencontroller.lyzr.com/blog/govern-ai-agents-on-kubernetes.md)
- [How should AI agent pods on Kubernetes get cloud credentials?](https://opencontroller.lyzr.com/blog/kubernetes-workload-identity-for-agent-pods.md)
- [How do you control which websites and APIs an AI agent can reach?](https://opencontroller.lyzr.com/blog/control-ai-agent-network-egress.md)
- [More on Platform Guides](https://opencontroller.lyzr.com/blog/cluster/platform-guides)
