Skip to content

Self-Hosted Sandbox: Kata Containers, Kubernetes agent-sandbox, BYOC

Aug 30, 20261 min
TL;DRThe self-hosted post (order 17) of the Sandbox Series. Kata Containers, Kubernetes-sigs/agent-sandbox, and BYOC model for enterprise self-hosted sandbox selection, architecture, and migration strategy, plus build-vs-buy decision framework.

Look up & save

Loading dictionary…

🌏 中文版

What This Post Is

This post is the "self-hosted" post (order 17) of the Sandbox Series. It doesn't compare single managed providers (in order 7–16), but focuses on enterprise self-hosted sandboxing:

  1. Kata Containers — OCI-compliant lightweight VM containers
  2. Kubernetes-sigs/agent-sandbox — Kubernetes-native sandbox controller
  3. BYOC (Bring Your Own Cloud) — Deploy sandbox control plane on own cloud
  4. Build vs. buy decision framework — When to self-build vs. use managed
  5. Migration strategy — From managed to self-hosted, or vice versa

Kata Containers

What is Kata Containers

Kata Containers is an OCI (Open Container Initiative) compliant lightweight VM container. Each Pod is a micro VM, each workload has its own minimal kernel, they don't share the kernel.

Architecture

┌─────────────────────────────────────┐
│           Kubernetes                 │
│  - Kata RuntimeClass                  │
│  - Pod scheduling                     │
└─────────────────────────────────────┘
           │
┌─────────────────────────────────────┐
│          Kata Runtime                 │
│  - One micro VM per Pod               │
│  - Independent kernel                 │
└─────────────────────────────────────┘

Integration with Docker / containerd

Kata Containers can integrate with containerd as a RuntimeClass in Kubernetes:

apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
  name: kata
handler: kata
---
apiVersion: v1
kind: Pod
metadata:
  name: untrusted-agent
spec:
  runtimeClassName: kata
  containers:
  - name: agent
    image: agent-image:latest

Pros and Cons

ProsCons
Hardware-level isolation (one VM per Pod)Slower startup (~200ms)
Native Kubernetes integrationHigher memory overhead
OCI compliantRequires KVM support
GPU passthroughHigher operational complexity

Kubernetes agent-sandbox

What is agent-sandbox

kubernetes-sigs/agent-sandbox is the Kubernetes community's official sandbox controller, designed specifically for AI agent execution environments. It decouples workload lifecycle management from isolation backend selection.

Core Features

1. Lifecycle Management

The agent-sandbox controller handles the full sandbox lifecycle: creation, scheduled deletion, pause (hibernation), auto-resume (on network connection).

apiVersion: agent.sigs.k8s.io/v1alpha1
kind: Sandbox
metadata:
  name: agent-sandbox-01
spec:
  runtimeClass: kata
  hibernation:
    enabled: true
    idleTimeout: 300s
  persistentStorage:
    size: 10Gi

2. Pluggable Isolation Backend

Supports standard containers, gVisor, Kata Containers, and other OCI-compliant runtimes.

3. Python and Go SDK

Provides high-level client libraries for programmatic sandbox management.

Guest Agent

agent-sandbox is developing a "Guest Agent" — a lightweight daemon running inside each sandbox Pod, providing lifecycle hooks (freeze, fsfreeze, collapse, init), ensuring snapshot state consistency and optimizing resume latency.


BYOC (Bring Your Own Cloud) Model

What is BYOC

BYOC means enterprises deploy sandbox control plane on their own cloud (AWS, GCP, Azure, or on-premises), rather than using managed provider cloud services.

Why Choose BYOC

ReasonDescription
Data sovereigntyData must stay in specific region or self-owned infrastructure
Compliance requirementsStrict compliance for finance/healthcare
Existing infrastructureEnterprise already has Kubernetes cluster, no extra cost
Network controlFull control over network policy and firewall

Implementation Options

  1. OpenSandbox BYOC: Alibaba Cloud OpenSandbox supports deploying control plane on AWS, GCP, Azure
  2. Kata + Kubernetes self-hosted: Build with Kata Containers + Kubernetes agent-sandbox
  3. E2B Embed: E2B provides self-hosted version (E2B Embed), runnable on own cloud

Build vs. Buy Decision Framework

Decision FactorChoose Managed SandboxChoose Self-Build
Scale< 10K executions/month> 1M executions/month
Engineering teamNo dedicated infra teamHas platform engineering team
Compliance requirementsGeneral complianceStrict compliance (finance/healthcare)
Data sovereigntyData can cross bordersData must stay within borders
Time to marketNeed to launch immediatelyCan spend months building
Cost sensitivityWilling to pay premium for convenienceWant to reduce long-term unit cost

Total Cost of Ownership (TCO) Comparison

Cost ItemManaged SandboxSelf-Hosted Sandbox
Compute resourcesPay-per-useSelf-owned infrastructure amortized
Engineering laborMinimalRequires dedicated team
Operational overheadProvider responsibleSelf-responsible
Upgrades and maintenanceProvider responsibleSelf-responsible
Compliance certificationsProvider providedSelf-obtained

Rule of thumb: If monthly sandbox executions < 10K, managed sandbox TCO is usually lower; if > 1M/month, self-build may be more economical but requires dedicated team.


Migration Strategy

From Managed to Self-Build

  1. Abstract sandbox interface: Build abstract interface at application layer, wrap specific provider SDKs
  2. Standardize images: Use OCI container images for easier migration across environments
  3. Externalize state: Store sandbox state in external storage services, not inside sandbox
  4. Gradual migration: First migrate non-critical workloads, verify, then migrate critical workloads

From Self-Build to Managed

  1. Evaluate managed providers: Compare E2B, Daytona, Modal, Bedrock AgentCore, etc.
  2. Export images and state: Export self-hosted sandbox images and state
  3. Test and verify: Test agent workflows in managed environment
  4. Switch traffic: Gradually switch traffic to managed sandbox

What You Should Understand After Reading

  1. Kata Containers architecture and Kubernetes integration.
  2. agent-sandbox core features and Guest Agent role.
  3. BYOC model definition and applicable scenarios.
  4. Build vs. buy decision framework and TCO comparison.
  5. Migration strategy: from managed to self-hosted, or from self-hosted to managed.

References