CubePod – E2B-compatible sandboxes with persistent rootfs on K8s

CubePod is an open-source, persistent MicroVM execution platform for high-autonomy AI agents, now at v0.8.1.
Within the CubePlex open-source stack, CubePod serves as the execution layer ("Hands") in a decoupled "Brain and Hand" architecture alongside CubePlex (Team Agent Workspace) and CubeLoop (Async Agent Runtime). CubePod targets a specific engineering goal: running on native Kubernetes CRDs and CSI block storage, maintaining wire compatibility with official E2B SDKs, and ensuring full RootFS modifications survive node crashes and cross-node rescheduling.
The Open-Source Agent Sandbox Landscape
Several open-source sandbox projects address isolated code execution for AI agents, each making different choices around control planes, scheduling, isolation, and persistence:
- E2B Runtime (
e2b-dev/runtime): A Go control plane (API,client-proxy, and per-nodeorchestratorrunning on Nomad/Consul with PostgreSQL, Redis, ClickHouse, and object storage) driving Firecracker microVMs. Templates and paused sandboxes are stored as full VM snapshots (memory + disk + machine state) in object storage. Creation and resume restore these snapshots viauserfaultfdlazy paging and a CoW rootfs overlay, achieving extremely fast startup and resume times. - CubeSandbox (
TencentCloud/CubeSandbox): A vertically integrated KVM MicroVM stack comprising CubeAPI, CubeMaster, Cubelet, CubeShim, CubeHypervisor, and XFS reflink-based CubeCoW. Even in its Kubernetes deployment (v0.6+), Kubernetes only delivers the control plane and node DaemonSets (cube-node); CubeMaster schedules KVM MicroVMs directly on host nodes rather than modeling each sandbox as a Kubernetes Pod and CRD (see OpenSandbox vs. CubeSandbox Selection). - Kubernetes
agent-sandbox(kubernetes-sigs/agent-sandbox): The official Kubernetes SIG Apps orchestrator providingSandbox,SandboxTemplate,SandboxClaim, andSandboxWarmPoolCRDs. It delegates isolation to CRIRuntimeClass(such as gVisor or Kata Containers) and storage to standard PVCs. It is strictly an orchestrator—it does not ship an in-sandbox execution daemon, stateful code interpreter, E2B-compatible API, or zero-trust egress secret vault. - OpenSandbox (
opensandbox-group/OpenSandbox): Built around a FastAPI lifecycle server (server/), OpenSandbox supports two distinct architectures on Kubernetes:- K8s-Native Container Workload (
BatchSandbox/Pool/SandboxSnapshotoragent-sandboxprovider): Each sandbox runs as a standard Kubernetes Pod with optional PVCs. On pause, a commit Job packages the container's writable rootfs into an OCI image and pushes it to a container registry; on resume, a new Pod boots from that snapshot image. - Fast Sandbox Integration (
fast-sandbox): For template-backed requests (templateIdorfsb-IDs),CompositeSandboxServiceroutes lifecycle operations to an externalFastPathgRPC control plane andsandbox.fast.ioCRDs, packing multiple Firecracker microVMs inside pre-warmedFastletpods with P2P artifact delivery (DART), bypassing per-sandbox Kubernetes scheduler and kubelet hot paths.
- K8s-Native Container Workload (
| Platform | Control Plane & Scheduling | Execution Unit | RootFS Persistence & Crash Durability | E2B Compatibility |
|---|---|---|---|---|
| E2B Runtime | Nomad/Consul + custom API/Orchestrator | Firecracker MicroVM | Diffs memory/disk to object storage only on Pause; node crash loses unpaused RootFS writes | Native standard |
| CubeSandbox | CubeMaster + node Cubelet (K8s for delivery only) | Node-local KVM MicroVM | Node-local full VM memory & disk snapshots (XFS reflink) | Compatible |
K8s agent-sandbox | Native K8s CRDs (Sandbox / WarmPool) | K8s Pod + RuntimeClass | Standard PVCs only; no RootFS persistence | None |
| OpenSandbox (K8s-Native) | FastAPI Server + BatchSandbox Controller | K8s Pod + RuntimeClass | Commits writable layer to OCI Registry on Pause | Not compatible |
| OpenSandbox (FastSandbox) | FastAPI + FastPath gRPC + Fastlet | Multi-VM inside Fastlet Pod | Template & node-local state roots with checkpointing | Not compatible |
| CubePod | Native K8s CRDs (PodBox / PodWarmPool) + stateless Gateway | Kata MicroVM Pod (kata-clh / kata-qemu) | Block-backed RootFS + RWO Block or RWX /workspace; survives node crashes | Compatible |
Tradeoffs in Operations, E2B Compatibility, and Node Failure Recovery
Deploying long-lived autonomous agents in production highlights three gaps across existing approaches:
1. Custom Cluster Operations vs. Existing Kubernetes Infrastructure
E2B delivers impressive cold-start and snapshot-resume latency, but operating a dedicated stack of Nomad, Consul, PostgreSQL, Redis, ClickHouse, object storage, and node-level orchestrator daemons adds significant operational burden. Most platform teams already run Kubernetes with established CSI storage, RBAC, monitoring, and network policies. Introducing a separate scheduling plane (E2B's Nomad stack or CubeSandbox's CubeMaster/Cubelet) forces teams to maintain parallel observability, capacity planning, and node-lifecycle tooling.
2. Data Loss on Node Crash Between Pauses
In E2B, persistence of the root filesystem relies on diffing memory and disk and uploading the delta to object storage when pause is invoked. While a sandbox is Running—including after resuming from an earlier pause and before the next pause completes—writes to the rootfs live on that host node's local overlay. If the node crashes, loses power, or is preempted before the next pause, any unpaused RootFS modifications are lost.
Similarly, OpenSandbox's K8s-native path persists the container rootfs by running an OCI commit/push Job at pause time, which incurs tens of seconds of export latency and does not protect unpaused container writable layers against sudden node failure.
3. Ephemeral RootFS in Standard Kubernetes Containers
When using standard Pods or agent-sandbox with a single PVC mounted at /workspace, any Pod eviction, scale-down, or cross-node reschedule discards system packages installed under /usr, /etc, and /var (apt, pip, npm, compilers, browser libraries). Conversely, coupling OS files and user code into a single volume prevents resetting a corrupted OS environment without risking /workspace data.
CubePod Design Goals and Core Tradeoffs
Most sandbox orchestrators treat cold-start and resume latency as their primary optimization target, keeping active filesystem writes in node-local overlays or local snapshots and syncing them only on an explicit pause. For long-lived agents that operate a dedicated cloud computer over days or weeks (such as Grokbot or Cue), losing installed system packages, browser sessions, local configurations, and workspace artifacts to a sudden host failure is far more disruptive than waiting an extra second on resume.
CubePod explicitly prioritizes zero data loss over sub-100ms resume latency: in a decoupled "Brain and Hand" architecture, the agent's reasoning state and conversation history are already persisted by the external control plane (such as CubeLoop or CubePlex). During sleep, the sandbox does not need to preserve guest RAM; it only needs distributed storage guarantees that preserve full-disk state (RootFS + Workspace) across node failures.
This leads to four core design decisions:
- First-Class Kubernetes Primitives: Every sandbox is a
PodBoxCR (cubepod.io/v1alpha1) backed by a standard Kubernetes Pod running Kata Containers (kata-clhCloud Hypervisor recommended, orkata-qemu) and persistent PVCs.cubepod-gatewayis stateless HA, reading authoritative state from Kubernetes CRDs and annotations. - Block-Backed RootFS & Flexible
/workspaceStorage: Rather than relying on node-local overlays and pause-time exports, CubePod mounts the RootFSupperdiron avolumeMode: BlockPVC viavirtio-blk(ext4), while/workspacesupports both RWO Raw Block (exclusive high-IOPSvirtio-blk) and RWX shared storage (viacubepod-volume-nfsNFSv3 or RWX PVCs for multi-sandbox sharing). Writes persist continuously to distributed storage backends (such as Longhorn V2 SPDK, Ceph RBD, OpenEBS Mayastor, or cloud EBS/NFS). If a node dies mid-execution, Kubernetes reschedules the Pod on a healthy node and re-attaches both volumes with zero disk data loss. - E2B Wire Compatibility: The in-guest Rust daemon
podd(:49983) andcubepod-gateway(:8080) implement E2B's REST and Connect-RPC contracts (/process.Process/*,/filesystem.Filesystem/*), allowing officiale2bande2b-code-interpreterSDKs to connect by simply settingE2B_DOMAIN. - Kubernetes & Local Docker Parity: Production uses
Kata + CSI Block; local development usesdocker-loopbackwith sparse.ext4loopback files, executing the exact samepodd-initandpoddbinaries.
Decoupled RootFS & /workspace Storage and In-Guest RootFS Pivot (podd-init)
Standard Kubernetes mounts volumeDevices after the container's rootfs is already prepared by containerd. To mount a raw block device as the container's writable RootFS layer without patching Kubelet or writing custom containerd snapshotters, CubePod uses an In-Guest RootFS Pivot.
1. OS/Workspace Decoupling and rootfsGeneration Reset
| Storage Layer | Backing Volume | Guest Mount Target | Lifecycle & Isolation Semantics |
|---|---|---|---|
| Base OCI Layer | Standard OCI image (ubuntu:24.04) | OverlayFS lowerdir=/ (RO) | Node-shared read-only cache; user images stay completely clean. |
| RootFS Upper | 10Gi CSI Raw Block PVC (rootfs-pvc) | OverlayFS upperdir + workdir | Persists /usr, /etc, /var (apt/pip/npm installs). |
| Workspace | RWO Block PVC (exclusive) or RWX shared volume (cubepod-volume-nfs / RWX PVC) | Mounted at /workspace (1000:1000) | Stores project code, artifacts, and /workspace/.skills; choose exclusive high-IOPS block or multi-sandbox RWX sharing. |
If an agent breaks system shared libraries or needs a base image upgrade, calling POST /sandboxes/{id}/reset-rootfs (or incrementing PodBox.spec.rootfsGeneration) instructs cubepod-controller to replace <box>-rootfs-gen<N>-pvc while re-attaching the existing /workspace volume (whether RWO Block or RWX shared) untouched.
2. Single-Threaded Rust podd-init and Binary Injection
- Zero Image Pollution: User images require no CubePod binaries baked in.
cubepod-podd(< 1MB,busybox:1.37-musl) injectspodd-initandpoddinto/opt/cubepod/binvia aninitContaineremptyDir(or an optionalhostPathDaemonSet introduced in v0.8.1 to skip initContainer overhead). - Single-Threaded PID 1 Requirement: Linux
pivot_root(2)returnsEINVALif the calling process has concurrent OS threads sharing its mount namespace. Because the Go runtime spawns background threads beforemain(),podd-init(crates/podd-init/) is written in single-threaded Rust using directlibc::mount(2)syscalls. - Self-Healing Boot:
podd-initisolates mount propagation, probes block devices viablkid, runs lazymkfs.ext4on first boot or mounts directly on wake withe2fsck -pfallback on mount failure (optimized in v0.8.1), assembles OverlayFS, mounts/workspace, bind-mounts/proc,/sys,/dev,/run, and/opt/cubepod, executespivot_root, detaches the old root, andexecvps intopodd(:49983) as PID 1.
Zero-Export Suspend, PodWarmPool, and CoW Fork
1. Zero-Export Hibernation and ~1s Cross-Node Resume
When a sandbox hits idleTimeoutSeconds or receives a pause request, podd flushes dirty pages (sync + FIFREEZE), and the controller deletes the Kata Pod. Compute usage drops to 0 CPU / 0 RAM without pushing OCI layers or multi-GB memory dumps. Any subsequent request to cubepod-gateway flips desiredState back to Running; Kubernetes schedules a new Pod on any available node, re-attaches both PVCs, and podd-init mounts the ext4 volumes in ~1 second (accelerated in v0.8.1 via K8s Pod watches, per-box parallel reconciliation, and direct PodIP:49983/health probing).
2. PodWarmPool (< 50ms Cold Starts)
Kubernetes prohibits mutating spec.volumes on an already-running Pod. PodWarmPool solves this by maintaining standby Kata MicroVMs that already have pre-created, thin-provisioned dual block PVCs attached and pivoted into ext4. When a creation request arrives, cubepod-controller atomically claims a standby Pod and its volumes via Kubernetes optimistic-locking CAS labels in under 50ms, then asynchronously replenishes the pool.
3. Crash-Consistent CoW Fork (spec.forkFrom)
To support speculative sub-agent branching without affecting the parent sandbox, POST /sandboxes/{id}/fork executes a bounded quiesce-and-clone sequence in ~1 second:
[ 1. Client Issues Fork Request ] POST /sandboxes/{id}/fork
│
▼
[ 2. Quiesce Parent Filesystem ] podd invokes FIFREEZE (with 1.5s watchdog)
│
▼
[ 3. CSI Block CoW Clone ] Clones via DataSourcePVC / Snapshot
│
▼
[ 4. Immediate Parent Thaw ] Sends FITHAW to restore parent workload I/O
│
▼
[ 5. Schedule Child Pod ] Boots CUBEPOD_FORKED=1, auto-heals ext4
│
▼
[ 6. Child Sandbox Ready ] New PodBox with isolated IP & state
Zero-Trust Egress and E2B Protocol Extensions
1. Secret Exclusion and Selective mTLS Token Swapping
Genuine external API keys never enter sandbox environment variables, filesystems, or process memory:
- Variables configured via
secretBindingsare injected as opaque reference placeholders. - An unprivileged
cubepod-egresssidecar (UID65532) pairs withnftablesto intercept outbound HTTP (:18081), TLS (:18443), and DNS (:18053), dropping UDP443(QUIC bypass) and returningRCODE=5for unauthorized DNS queries. - Traffic to unbound allowlisted hosts uses zero-copy TCP splicing (
spliceUpstream). Only hosts bound to secrets undergo selective TLS/HTTP2 ALPN MITM (HTTP Host == TLS SNIverified), swapping placeholder tokens in flight via per-pod ECDSA P-256 mTLS againstcubepod-gateway.
2. E2B Superset & Unified /volumes
Alongside full compatibility with e2b and e2b-code-interpreter (6 stateful kernels: Python, JS, TS, R, Java, Bash), CubePod adds stateless byte-cursor log streaming (GET /commands/{pid}/logs?cursor=N), < 50ms in-memory skill archive-sync, HMAC-signed /panel/{token}/ proxying (Chromium CDP, Neko WebRTC, ttyd), and unified /volumes (type: "shared" | "block", with cubepod-volume-nfs NFSv3 transport for shared volumes across Firecracker/Kata and CAS attach-lease fencing for block /workspace in v0.8.0).
CubePod Strengths, Tradeoffs, and Scope
Strengths
- Node-Crash Durability Without Pausing: Continuous writes to distributed CSI Raw Block volumes for RootFS (and RWO Block or RWX shared storage for
/workspace) mean OS and project state survive unexpected node crashes, kernel panics, or Pod evictions—not just cleanpausecalls. - Native Kubernetes Operations: Every sandbox is a standard
PodBoxCR and Kata Pod scheduled by Kubernetes, inheriting existing CSI storage, RBAC, NetworkPolicy, Prometheus metrics, and Helm lifecycle management without operating Nomad/Consul or a custom VMM scheduler. - Decoupled OS Reset & Clean Images:
rootfsGenerationrepairs broken OS packages without touching/workspace, while standard OCI images run unmodified. - E2B Drop-In + Built-In Secret Exclusion: Zero-code migration for E2B SDK consumers, combined with in-pod mTLS credential swapping.
Tradeoffs and Limitations
- No Guest RAM or Process State Across Pause: This is an explicit tradeoff for staying strictly Kubernetes-native without out-of-tree Kubelet or runtime patches. Native Pod-level memory checkpoint/restore depends on upstream Kubernetes Pod Checkpoint/Restore support, which is not expected to reach Alpha until Kubernetes 1.38. Until then, CubePod deletes the Pod on pause rather than bypassing Kubernetes Pod scheduling; consequently, running background processes, open sockets, and in-memory interpreter variables are lost on pause/resume. Workloads requiring live process continuation across sleep are better served by E2B or CubeSandbox's full memory snapshots.
- Resume Latency (~1s) vs. Local Memory-Snapshot Resume (< 100ms):
PodWarmPooldelivers< 50mscold starts for new blank sandboxes, but resuming an existingPausedsandbox requires K8s scheduling, CSI volume attachment, andpodd-initmounting (~1s), which is slower than E2B or CubeSandbox resuming cached local snapshots viauserfaultfd/mmap. - Kubernetes Infrastructure Prerequisites: Full hardware-isolated block persistence requires Kata Containers and a CSI driver supporting
volumeMode: Blockand snapshots (Longhorn V2 SPDK, Ceph RBD, OpenEBS, or cloud EBS).kata-clh(Cloud Hypervisor) is recommended for production;kata-fc(Firecracker) currently has a knownvirtio-mmiohotplug race (#120). Clusters without Kata or Block CSI fall back tovolumeMode: Filesystem(without RootFS persistence). - Storage Overhead for Short-Lived Stateless Tasks: Provisioning a persistent block PVC for RootFS adds unnecessary CSI attach/detach overhead for ephemeral, sub-minute tasks that do not need OS persistence; plain container pools (e.g., OpenSandbox
Pool) are lighter for purely stateless workloads.
Repositories and Deployment
CubePod is open-source under the Apache 2.0 License:
- GitHub: cubeplexai/cubepod (current release
v0.8.1) - Documentation: cubepod.dev
- Enhancement Proposals (CEPs): docs/enhancements
- Deployment: Production Helm chart at
deploy/helm/cubepod(Kata + CSI Block) and single-hostdeploy/docker-compose(docker-loopbackmode).
Open-source projects
Bring agents into your team's day-to-day work
CubePlex
A self-hosted AI agent workspace for teams to handle document, data, and cross-system work with centralized access control and execution records.
View CubePlex sourceCubeLoop
A high-performance, traceable, async-native Python agent framework with production-grade persistence.
Visit CubeLoop