Agent Sandboxes: Lightweight Control Plane and Layered Storage
Agent sandboxes must run tools, access files, and execute code in isolation from the host and from other tasks. At scale, a heavy control plane built from a database, message queue, service discovery, and distributed locks creates coordination overhead on every create, pause, and resume. This article presents a lighter model: single-process orchestration per node, with recoverable state stored in the filesystem and layered block devices. It separates the isolation runtime, control plane, and storage/image supply; walks through a single-node create-and-execute path; explains how read-only base layers and writable upper layers improve startup, memory sharing, pause, and recovery; and discusses how this model fits under a larger scheduler. It also covers crash consistency, resource overcommit, security boundaries, and a staged rollout sequence.
Agents call tools, read and write files, and execute code, so their runtime must be isolated from the host and from other tasks. At scale, the platform easily grows into a heavy control plane made of a database, a message queue, service discovery, and distributed locks. Creating a sandbox then requires agreement across multiple components, and pausing or resuming requires extra state synchronization. A more robust path is to collapse the control plane into single-process orchestration and place recoverable state in the filesystem and layered block devices. The sections below cover responsibility boundaries, runtime shape, storage model, and operational constraints.
1. Start by Separating Three Layers of Responsibility
When discussing a sandbox platform, it helps to separate three concerns so that “it can run” is not confused with “it can serve as a production foundation.”
The first layer is the isolation runtime. Each task runs in an independent lightweight VM or an isolation boundary of comparable strength, with its own kernel view, network namespace, and block device. If an agent process crashes, corrupts its disk, or saturates CPU, other tasks on the host should not be directly affected.
The second layer is the control plane. It accepts requests to create, execute commands, upload and download files, run health checks, pause, resume, and destroy, and translates those requests into runtime operations. The control plane should keep transactions short and have a clear design for horizontal replication; it should not become a business database itself.
The third layer is storage and image supply. Read-only base images, writable diff layers, paused state, and snapshots determine cold-start speed, memory footprint, and whether a task can continue after interruption. In training or evaluation scenarios, this layer often affects throughput more than the API gateway.
In open-source or self-built deployments, a common division is that the storage path can be exposed and reused fairly completely, while solutions tightly bound to a specific data center, distributed filesystem, or memory-mapping optimization remain in private infrastructure. Therefore, seeing one storage-layer implementation should not be taken as receiving an entire production platform.
2. Why the Control Plane Can Be “Light”
Light is not about fewer features; it is about a narrower consistency scope. On a single node, one orchestrator process can complete the following loop:
- Provide HTTP interfaces, plus WebSocket where necessary, for authentication, quotas, and request routing.
- Create isolated VMs from templates and inject environment variables, resource limits, and the entry process.
- Create an independent network for each sandbox: a network namespace, virtual NIC, and host-side forwarding interface, with cross-sandbox traffic denied by default.
- Attach layered block devices: a read-only base layer and a writable diff layer exclusively owned by that sandbox.
- Route client command execution, file access, and health reports through a reverse proxy to a daemon inside the VM.
With this shape, a single node does not need to deploy a database, message queue, service discovery, or a quorum component. Paused sandboxes, snapshots, and templates are represented as files or layers on block devices. After a process restart, scanning the configured directories and device mappings is enough to reconstruct which sandboxes exist and whether they are running or paused. This is the idea of the filesystem as the source of truth: the in-memory table is only a cache that can be rebuilt, while what must not be lost are the layer files, the cleanup of leftover network configuration, and disk quota records.
The cost is also clear. Cross-node scheduling, global quotas, and replicated metadata cannot be solved by scanning local directories. The single-node model fits development machines, small-scale evaluation, and an architecture in which one scheduler manages multiple independent nodes. Do not share writable layers across nodes, and do not let two orchestrator processes modify the same set of layer files at the same time.
3. Single-Node Request Path
A typical create-and-execute flow can be kept short, avoiding distributed transactions on the critical path.
- The client submits a template ID, resource specification, timeout, and network policy.
- The orchestrator allocates a sandbox ID, prepares a read-only baseline and an empty writable layer, and writes the device mappings.
- It launches the isolated VM and waits for the in-VM daemon to report readiness.
- The reverse proxy forwards subsequent command and file requests to that instance, and results are streamed back.
- On expiration, failure, or explicit destruction, the VM is stopped first; then the writable layer is retained or deleted according to policy.
A schematic split of responsibilities (structure only, not a product API) can look like this:
client -> api -> orchestrator|-> create isolated vm|-> setup netns / tap|-> attach layered block (ro base + rw upper)vm-agent <-- reverse proxy <-- client (exec / files / health)
The daemon should do only three small things: execute controlled commands, read and write the workspace according to policy, and report health periodically. It should not decide image layering or host networking; otherwise the isolation boundary will be breached.
4. Layered Storage Is the Lever for Scaling
Sandbox images are often highly similar: the base system, language runtime, and common tools account for the vast majority of bytes, while only a small number of files and package-install results differ from task to task. If every sandbox copies a full disk image, node memory and disk fill up from images before they fill up from compute.
The basic conventions for layered block devices are:
- A read-only base can be shared by many sandboxes, which suits page-cache sharing and reduces duplicate reads.
- A writable upper layer is isolated per sandbox, so writes do not pollute the baseline, and destroying the sandbox only discards the upper layer.
- When a workload needs to continue from a particular point in time, commit the upper layer as a snapshot or a new read-only layer, then derive the next writable layer from it.
- Pausing does not require treating all VM memory as the only state; filesystem state that can be persisted to a block device is easier to inspect and migrate on recovery.
Read-only sharing creates room for memory overcommit: when multiple VMs map the same baseline, the host can keep only one copy of hot pages. The overcommit ratio depends on whether working sets actually overlap and should not be written into capacity planning as a fixed multiplier. Once writes diverge—for example, when every task installs many dependencies or writes logs to the system disk—the benefit of sharing declines quickly. Logs and large data outputs should be directed to separate volumes or external object storage.
Another class of optimization is to expose read-only images as a read-only filesystem better suited to direct access, paired with persistent memory inside the guest or direct-access paths, to reduce duplicate caching in both guest and host page caches. Such schemes are usually tied to specific virtualization devices and kernel versions, with higher deployment and troubleshooting costs. They are better introduced after the storage path is stable, not as a prerequisite for the first version of the control plane.
5. Working with a “Heavy Platform” Instead of Replacing It
A lightweight control plane does not reject an outer platform; it keeps that platform outside the sandbox lifecycle.
- Task queues, experiment orchestration, and evaluation scoring live outside the sandbox platform. The platform only guarantees: given a specification, return an executable environment.
- Image builds use an independent pipeline to produce immutable bases; the sandbox runtime should not assemble very large images ad hoc on the hot path.
- Cross-node scheduling is handled by an upper-level scheduler: it selects a node and then calls that node’s local API. The node itself does not maintain global membership.
- Audit logs, metrics, and traces are sent to external logging and monitoring systems; nodes keep only short-lived troubleshooting information, avoiding a database in the control plane just to query history.
- Secrets and tool credentials are injected per task and reclaimed per task, not written into the read-only baseline.
If sandboxes are exposed directly to the public internet, the reverse proxy must perform identity verification, bind requests to the target sandbox, and restrict protocols; clients must be forbidden from specifying arbitrary upstream addresses. Default egress should also be narrowed with per-task allowlists; otherwise isolation remains only at the process level while data can still leak.
At larger scale, image registries, snapshot archives, and runtime logs can use general cloud services such as object storage, log services, and monitoring and alerting. For example, with a public cloud platform, a node can keep only hot layers and running VMs while cold snapshots and audit logs are externalized, so a disk failure on one node does not simultaneously destroy all history. Even after externalization, the control plane still stores no business state; it stores only pointers to where the layers are and ensures those pointers match the actual files.
6. Design Boundaries That Are Easy to Miss
The filesystem as the source of truth depends on clear write ordering and crash consistency. Layer files, VM configuration, and network devices must be created and deleted in a fixed order. During crash recovery, clean up half-started NICs and processes first, then decide whether to replay an unfinished creation. Do not guess in the recovery path whether upper-layer business logic succeeded; restore only the state that the infrastructure can prove.
Writable layers are not backups. Task inputs and outputs should have independent object versioning, and the sandbox destruction policy should state how long layers are retained. Paused states consume disk and memory handles and must be reclaimed on timeout; otherwise, the lightweight control plane will fill directories with instances that still look present.
Resource overcommit must consider CPU, memory, and disk bandwidth together. Read-only page sharing relieves duplicate baseline memory, but it does not relieve random writes and log writes. For workloads such as training or reinforcement learning that launch many short-lived environments concurrently, cap the number of concurrent creations per node and leave a queue for device mounting and VM startup, so a creation storm does not saturate host I/O.
On security, the daemon inside the VM should have less privilege than the host orchestrator. By default, the file API should be limited to the workspace, and path traversal must not allow access to layer devices or other sandboxes. Command execution needs timeouts, output size limits, and non-interactive constraints. These limits are platform invariants and should not be something the upper-layer agent can turn off.
7. Recommended Rollout Sequence
Proceed from lower to higher risk, rather than piling on memory optimizations and a distributed backend all at once.
- Complete a single-node path for create, execute, and destroy, with state stored only in local directories.
- Add network isolation and the reverse proxy; verify that sandboxes cannot reach one another.
- Introduce read-only base + writable upper layers and measure startup latency and memory delta with real task images.
- Define pause, snapshot, and reclamation policies, and run crash-recovery drills.
- Only then evaluate read-only filesystems and more aggressive memory paths; introduce a distributed file backend only when sharing read-only layers across multiple nodes shows clear benefit.
- Connect the upper-level training or evaluation scheduler, while keeping the platform itself free of queues and elections.
With these pieces separated, “light control plane” has a testable meaning: the create path does not depend on external consensus; after a restart, the view can be recovered from files; what is shared is read-only data, while writable layers and network are isolated. Each storage optimization should be independently switchable and validated against startup time, memory delta, and failure-recovery time—not by architecture jargon replacing capacity planning.
