Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 14 min read

Self-Hosted AI Agent Sandboxes (2026): Isolation Runtimes, Kubernetes Options, and the Controls You Build Yourself

Self-hosting an AI agent sandbox means choosing an isolation runtime, such as a user-space kernel like gVisor or a microVM like Kata Containers or Firecracker, and running it on nodes that support it. You then build egre

Self-hosting an AI agent sandbox means choosing an isolation runtime, such as a user-space kernel like gVisor or a microVM like Kata Containers or Firecracker, and running it on nodes that support it. You then build egress, credential, resource, and cleanup controls around that runtime. Control Plane Sandboxes give you microVM isolation and persistent storage without building that stack.

Disclosure: Control Plane publishes this guide.

TL;DR

Self-hosting an AI agent sandbox starts with an isolation runtime and ends with operational controls that make up most of the work.

  • Plain containers share the host kernel, and GKE’s documentation warns that a flaw in the container runtime or host kernel could let a process escape the container.
  • gVisor adds a user-space kernel, needs no hardware virtualization, and relies on host cgroup limits on the pod. MicroVMs such as Kata Containers and Firecracker give each sandbox its own guest kernel and need hardware virtualization on the host.
  • Kubernetes RuntimeClass selects the runtime per pod, and kubernetes-sigs/agent-sandbox reached v1.0 in August 2026 with v1beta1 CRDs for stateful and warm-pooled sandboxes.
  • GKE offers gVisor and microVM runtimes, AKS supports Kata Containers on Azure Linux nodes, and EKS does not document a managed sandbox runtime.
  • Egress lockdown, metadata blocking, credential scoping, resource limits, cleanup, and audit are most of the engineering work.
  • Control Plane Sandboxes run in dedicated Kata Containers microVMs with persistent storage and no Kubernetes API access, and Control Plane workloads start with all network communication disabled, so you skip building that stack.

How do you self-host an AI agent sandbox?

Self-hosting means you own the full stack, from node provisioning and runtime installation to network policy, credentials, observability, and incident response.

  1. Pick the isolation runtime. Choose gVisor (user-space kernel, no hardware virtualization required), Kata Containers (lightweight VM with several VMM backends), Firecracker (microVM on KVM), or WebAssembly for narrow code-interpreter cases.
  2. Provision nodes that support your runtime. MicroVM runtimes need KVM. EC2 now supports nested virtualization on virtual instances in the M7i, M8i, C7i, C8i, R7i, R8i, X8i, and I7i families, so KVM no longer requires .metal instances, though AWS still recommends bare metal for latency-sensitive workloads. gVisor runs on any Linux node.
  3. Install the RuntimeClass and an orchestrator. Register a Kubernetes RuntimeClass with the right handler. For lifecycle management, install kubernetes-sigs/agent-sandbox, which provides Sandbox, SandboxTemplate, SandboxClaim, and SandboxWarmPool CRDs and delegates isolation to the RuntimeClass you chose.
  4. Lock down network, metadata, and credentials. Apply a default deny-all egress NetworkPolicy, route allowed traffic through an egress proxy with a hostname allowlist, and block the cloud metadata server. Set automountServiceAccountToken: false on every sandbox pod.
  5. Set resource limits, timeouts, and cleanup. Set CPU, memory, ephemeral-storage, and PID limits so a fork bomb or disk fill cannot starve the node. Define execution timeouts and destroy sandboxes after each task.
  6. Log and audit every sandbox. Ship logs outside the sandbox and record every agent action, network connection, and lifecycle event.

Which isolation runtime should a self-hosted sandbox use?

Each runtime trades isolation strength against startup cost, hardware requirements, and workload compatibility.

Runtime Isolation boundary Host requirement Documented startup GPU support License
Plain containers with seccomp Shared host kernel with a seccomp syscall filter Any Linux node Not documented Not documented Not applicable
gVisor (runsc) User-space kernel in Go implementing a subset of the Linux syscall ABI Any Linux node Not documented upstream (under 100 ms on GKE Sandbox) NVIDIA GPUs through nvproxy on preselected driver versions; specific GPU and TPU models on GKE Sandbox Apache 2.0
Kata Containers Lightweight VM with its own guest kernel Hardware virtualization (Intel VT-x, AMD SVM, Arm Hyp) Not documented Through VFIO passthrough; QEMU is the documented path Apache 2.0
Firecracker MicroVM with its own kernel KVM, or Nitro Enclaves instances as a Nitro Sandbox Under 125 ms, with under 5 MiB of memory overhead per microVM No (VFIO passthrough is an open feature request) Apache 2.0
WebAssembly (Wasmtime) Sandboxed by design; runs code compiled to WebAssembly Any node Not documented Not documented Apache 2.0 with LLVM exception

gVisor fits when you want broad Linux compatibility, fast startup, and no hardware virtualization dependency. It integrates with Docker and Kubernetes through its runtime, runsc. It adds cost for syscall-heavy workloads. Resource limits come from the host cgroup, since gVisor does not enforce them inside the sandbox. A microVM fits when you need a hard VM boundary with a separate guest kernel. Kata Containers supports QEMU, Cloud Hypervisor, Firecracker, Dragonball, and StratoVirt as its VMM. Production Firecracker runs each VMM under its jailer, which sets up a chroot, namespaces, cgroups, and an unprivileged user before starting the VMM, and Firecracker applies its own seccomp filters to its threads. Cloud Hypervisor, a Rust VMM on KVM or Microsoft Hypervisor, supports VFIO device passthrough. WebAssembly runtimes like Wasmtime need code compiled to WebAssembly, which fits narrow code-interpreter cases more than general coding agents.

No runtime removes every risk. MicroVMs and gVisor sandboxes still share host CPUs, so side channels remain a concern, and host kernels and VMMs get their own CVEs. For hostile multi-tenant code, run sandboxes on dedicated nodes per tenant tier and patch host kernels, guest kernels, and VMMs promptly.

How do managed Kubernetes services support sandboxed pods?

Support differs across the three major providers and self-managed clusters.

Platform Runtime and RuntimeClass Node requirements Documented limits
GKE Sandbox (gVisor) gVisor GKE Standard or Autopilot nodes Starts in under 100 ms; supports specific GPU and TPU models
GKE Sandbox (microVM) Kata Containers with Cloud Hypervisor, RuntimeClass microvm GKE Standard nodes with nested virtualization; not on E2 or Arm VMs Fixed overhead of 250 mCPU and 130 MiB per pod; starts in about one to two seconds; no GPUs or TPUs
AKS Pod Sandboxing Kata Containers, RuntimeClass kata-vm-isolation Azure Linux nodes only May not reach the IOPS of regular containers; no host-network access
EKS No documented managed sandbox runtime Bare metal or nested-virtualization instances for Kata Containers; any Linux node for gVisor AWS has shown Kata Containers on EKS worker nodes
Self-managed Kubernetes Any runtime through a RuntimeClass handler Depends on the runtime You own installation, upgrades, and compatibility testing

GKE’s documentation recommends resource limits on every sandboxed container and a NetworkPolicy that blocks the metadata server. Kubernetes Pod Overhead lets the scheduler account for runtime overhead when it places sandboxed pods.

What self-hostable sandbox projects exist in 2026?

The ecosystem includes a Kubernetes-native orchestrator, microVM runtimes, and agent frameworks with pluggable sandbox providers.

Project What it is License Self-hosting today
kubernetes-sigs/agent-sandbox Sandbox orchestrator for Kubernetes that delegates isolation to a RuntimeClass such as gVisor or Kata; CRDs Sandbox, SandboxTemplate, SandboxClaim, SandboxWarmPool; v1beta1 APIs (agents.x-k8s.io for Sandbox, extensions.agents.x-k8s.io for the other three) Apache 2.0 v1.0 since August 2026; needs Kubernetes 1.25 or later, 1.29 or later recommended
E2B runtime and E2B Embed Open-source runtime with one Firecracker microVM per sandbox and a per-sandbox egress firewall Apache 2.0 E2B Embed runs on a single Linux host with KVM; multi-node deployment in your cloud is a dedicated deployment E2B runs
Daytona Sandbox platform for AI-generated code AGPL-3.0 (last open-source release) Open-source repository archived after development moved to a private codebase in June 2026; current option is Bring Your Own Compute, with orchestration hosted by Daytona
microsandbox Library that embeds local microVMs in your code with no server or daemon Apache 2.0 Runs locally inside your application
OpenHands sandboxes Agent framework with Docker, process, and remote sandbox providers MIT The Docker provider is self-hostable; the process provider has no container isolation
Jupyter Kernel Gateway Headless access to Jupyter kernels, launched in its own process and filesystem space Modified BSD Needs a container or microVM around it to isolate code

What controls do you have to build yourself?

The isolation runtime is the foundation, and the controls around it are most of the engineering and operating work.

Control Kubernetes default What to set
Egress NetworkPolicy allows all egress by default and needs a network plugin that enforces it A default deny-all egress policy; route allowed traffic through an egress proxy that enforces a hostname allowlist and logs every request, or use FQDN policies in a network plugin that supports them
DNS A default deny-all egress policy also blocks DNS Allow the cluster DNS service explicitly, restrict it to names on your allowlist or a filtering resolver, and log queries, because open DNS can carry data out of the sandbox
Cloud metadata server Reachable from pods unless blocked Block 169.254.169.254/32 and, on AWS, fd00:ec2::254/128; block 169.254.170.23 and fd00:ec2::23 where EKS Pod Identity runs and 168.63.129.16 on Azure; add except entries to any broad allow rule; on EC2 nodes, require IMDSv2 with a hop limit of 1; GKE microVM pods without Dataplane V2 also need 169.254.169.252 on port 988 blocked
ServiceAccount token Mounted automatically unless automountServiceAccountToken: false Set automountServiceAccountToken: false on every sandbox pod, and block the API server and the node kubelet port 10250 in the egress policy
CPU and memory limits No limits unless set Set CPU, memory, and ephemeral-storage limits and a kubelet PID limit; CPU limits throttle and memory limits trigger OOM kills
Filesystem persistence and cleanup Pod filesystem is ephemeral Use persistent volumes only when needed, never reuse a volume across users or tenants, and delete sandbox pods after each task or timeout
Idle warm pools No warm pool mechanism in core Kubernetes Use SandboxWarmPool from agent-sandbox or build your own; hand each pre-warmed sandbox to one task, then destroy it, and never return a used sandbox to the pool
Image supply chain No image verification by default Sign and verify sandbox images, pin digests, and scan for vulnerabilities
Audit and logs API server audit logging depends on cluster configuration Ship sandbox logs outside the cluster and record agent actions, network connections, and lifecycle events
Pod security context Pods may run as root with default capabilities Enforce Pod Security Admission β€œrestricted” on sandbox namespaces, which requires non-root, all capabilities dropped, no privilege escalation, a RuntimeDefault seccomp profile, and no privileged, hostPath, hostNetwork, hostPID, or hostIPC settings; also set readOnlyRootFilesystem: true in each sandbox container
Node isolation Any pod can schedule on any node Run sandboxes on a dedicated node pool with taints and tolerations, away from system pods and workloads that hold secrets
Namespace and quota Pods share a namespace unless you separate them Give each tenant or sandbox its own namespace with a ResourceQuota and LimitRange
Lateral traffic Pods accept ingress from any pod Apply a default deny-all ingress policy and block sandbox-to-sandbox traffic
Credentials Secrets mount into pods when referenced Never inject secrets into a sandbox; let a proxy outside it attach short-lived credentials to approved requests
Timeouts Pods run until they exit Set activeDeadlineSeconds or an orchestrator timeout and kill the sandbox on expiry
Host and guest kernels You own node patching Patch host kernels, gVisor, Kata guest kernels, and VMMs on a fixed schedule

NetworkPolicy works at layer 3 and 4 on IP addresses, so a hostname allowlist needs an egress proxy such as Envoy or Squid, or FQDN policies in a network plugin that supports them. The proxy is also where you log every request and attach short-lived credentials, so secrets never enter the sandbox. Pair it with a filtering DNS resolver, because unrestricted DNS queries can carry data out even under a deny-all policy.

Warm pools cut startup latency for interactive agents, but every idle sandbox holds CPU, memory, and sometimes storage. On GKE, each microVM pod also carries a fixed overhead of 250 mCPU and 130 MiB. A pool sized for peak demand keeps paying for that capacity during quiet hours, so size it from measured demand.

When is self-hosting worth it?

Self-hosting pays off in specific cases, and each one comes with operating work.

Data residency and compliance. When regulations require that AI-generated code and the data it touches stay in your network or a specific jurisdiction, self-hosting gives you control of the nodes, storage, and network boundaries.

Private network access. Agents that reach internal databases, APIs, or services behind a private network are simpler to connect when the sandbox runs in the same network.

On Control Plane, you choose where each Sandbox runs through the locations of its Control Plane Global Virtual Cloud (GVC), and production agents can run on your own Kubernetes clusters through Control Plane’s Bring Your Own Kubernetes (BYOK), so residency and private network access do not require building the sandbox stack yourself.

Cost at sustained volume. At high, steady sandbox use, running your own nodes can cost less than per-sandbox pricing. The break-even point depends on utilization, instance pricing, and how tightly you manage warm pools and cleanup.

The operating work it adds. Self-hosting moves runtime upgrades, kernel patching, vulnerability response, observability, on-call, and capacity planning to your team. You also own compatibility testing between your Kubernetes version, runtime, network plugin, and orchestrator.

How does Control Plane run AI agent sandboxes?

Control Plane handles Day 2 operations for you, including autoscaling, built-in observability, and security.

It also covers most of the controls in the self-build table, including microVM isolation for Sandboxes, default-deny networking with outbound allowlists for workloads, no Kubernetes API access or tokens, and short-lived cloud credentials. Each workload is isolated with cgroups, namespaces, and restricted syscalls and capabilities, and Sandboxes run in dedicated Kata Containers microVMs. A Control Plane Sandbox is a cloud environment with a browser IDE, terminal, and persistent storage. Its /root directory is backed by a persistent volume set, so cloned repositories, tool settings, and other files under /root survive suspend and resume, and a suspended sandbox keeps only its storage. The Control Plane CLI command cpln sandbox connect opens it in VS Code, Cursor, SSH, a browser IDE, or a terminal. Sandboxes are for agents building and running untrusted code, and production agents run as Control Plane workloads.

Workloads start with no internal or external communication enabled, and outbound access can be opened to the whole internet or limited to specific CIDRs or hostnames. Workloads have no access to the internal Kubernetes API and no Kubernetes tokens. A metadata service provides short-lived cloud credentials based on the workload’s identity. Control Plane’s Universal Cloud Identity lets workloads call AWS, GCP, and Azure services with no long-lived cloud keys in your code. Workloads use mutual TLS with a unique client certificate per workload.

Production agents can run on your own Kubernetes clusters through BYOK, which registers a cluster as a location, or on Control Plane-managed locations. A GVC is Control Plane’s named set of locations across AWS, GCP, Azure, and Oracle Cloud Infrastructure regions, clusters you registered, and your own hardware. Control Plane is PCI DSS Level 1, SOC 2 Type II, HIPAA, and GDPR compliant.

The guide on how to choose an AI agent sandbox lists the evaluation criteria, the ranking of the best AI agent sandboxes in 2026 compares managed options, and the list of AI agent infrastructure platforms covers where production agents run.

FAQ

Each answer covers one decision in a self-hosted sandbox build, from runtime choice to cost.

What are the steps to self-host an AI agent sandbox?

Pick an isolation runtime (gVisor, Kata Containers, or Firecracker), provision nodes that support it, and install a Kubernetes RuntimeClass with an orchestrator such as kubernetes-sigs/agent-sandbox. Then lock down egress and credentials, set resource limits and cleanup, and ship logs outside the sandbox.

Is a Docker container secure enough for AI-generated code?

No. Plain containers share the host kernel. Docker applies a default seccomp profile, but Kubernetes pods run Unconfined unless the kubelet enables seccompDefault or the pod sets RuntimeDefault. GKE’s documentation warns that a flaw in the container runtime or host kernel could let a process escape the container. OWASP LLM05:2025 flags LLM output passed to a shell, exec, or eval as a path to remote code execution, so untrusted code needs a stronger boundary.

gVisor vs Firecracker vs Kata Containers: which should I use?

Use gVisor for broad compatibility without hardware virtualization, and a microVM (Firecracker or Kata Containers) when you need a separate guest kernel. gVisor implements a subset of the Linux syscall ABI and adds cost for syscall-heavy workloads. Firecracker documents startup under 125 ms and under 5 MiB of memory overhead per microVM, needs KVM, and has no GPU passthrough today. Kata Containers supports several VMMs, including QEMU for GPUs, and needs hardware virtualization.

Can I run microVM sandboxes on EKS, GKE, or AKS?

Yes on GKE and AKS as managed features, and on EKS with Kata Containers you install yourself. GKE Sandbox offers microVMs built on Kata Containers and Cloud Hypervisor (RuntimeClass microvm) alongside gVisor. AKS supports Kata Containers with RuntimeClass kata-vm-isolation on Azure Linux nodes. EKS does not document a managed sandbox runtime, so teams install Kata Containers or gVisor themselves.

What is Kubernetes Agent Sandbox?

Kubernetes Agent Sandbox (kubernetes-sigs/agent-sandbox) is a sandbox orchestrator maintained under SIG Apps that reached v1.0 in August 2026 with v1beta1 APIs. It provides four CRDs: Sandbox (a single stateful pod with stable identity and persistent storage), SandboxTemplate, SandboxClaim, and SandboxWarmPool. It delegates isolation to the RuntimeClass you configure, such as gVisor or Kata Containers, and needs Kubernetes 1.25 or later (1.29 or later recommended).

How do I stop a sandbox from reaching the internet or cloud metadata?

Apply a default deny-all egress NetworkPolicy and route allowed traffic through an egress proxy with a hostname allowlist, or use FQDN policies in a network plugin that supports them, because NetworkPolicy cannot match hostnames and has no effect without a network plugin that enforces it. Block the metadata server at 169.254.169.254 and, on AWS, fd00:ec2::254, plus the EKS Pod Identity and Azure WireServer addresses, and require IMDSv2 with a hop limit of 1 on EC2 nodes. Allow the cluster DNS service explicitly through a filtering resolver, because a deny-all policy also blocks DNS and open DNS can carry data out.

Should each sandbox get its own namespace?

Yes, in multi-tenant setups. A namespace per tenant or sandbox lets you scope a ResourceQuota, a LimitRange, and NetworkPolicy rules to it and label it for Pod Security Admission β€œrestricted”. It also limits what a compromised sandbox can see through the Kubernetes API.

Is self-hosting sandboxes cheaper than a managed service?

Sometimes, at sustained high utilization. At low or variable use, node costs, idle warm pools, and engineering time for upgrades, patching, and on-call can exceed managed pricing. The break-even point depends on utilization, instance pricing, and team capacity.

Does Control Plane offer sandboxes for AI agents?

Yes. Control Plane Sandboxes run in dedicated Kata Containers microVMs with persistent storage, a browser IDE, and terminal access, and Control Plane workloads start with no network communication enabled and no Kubernetes API access. cpln sandbox connect opens a sandbox in VS Code, Cursor, SSH, a browser IDE, or a terminal. Production agents run as Control Plane workloads on Control Plane-managed locations or on your own clusters through BYOK.

Talk to the Control Plane team about Sandboxes and production agent workloads, or sign up free to start building.

Originally published on the Control Plane blog.

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.