×

Labelbox•

Inside the RMA sandbox: where agents do their work

Inside the RMA sandbox: where agents do their work

When someone joins a team, one of the first things they get is a computer. It comes with the tools they need, it can reach the systems they're allowed to use, and their files are still there when they come back the next day.

Agents need the same thing. An agent that fixes code, runs tests, or analyzes files needs somewhere to run commands and keep its work. In Recursion Managed Agents (RMA), that place is the sandbox: a Linux workspace for commands, files, and, when enabled, a browser.

The architecture post introduced the sandbox as one part of RMA, and the post on access covered how agents reach other services without holding the keys. This post covers the sandbox itself: how it's created, how it's kept apart from other organizations' work, how it gets capacity, and what happens to it when the agent goes idle. Along the way, we'll follow the bug-fix job from the architecture post.

Under the hood, each sandbox runs as a Kubernetes pod, managed by a control plane we built for agent workloads.

From session to sandbox

From session to sandbox
RMA session

Main agent + subagents

  • Share a workspace by default
  • Environment sets the machine
Sandbox control plane

Admit and create

  • Checks the request fits
  • Creates the disk and pod
  • Watches until it's running
Commands

Runs inside the sandbox

  • Each command runs in the workspace container.
  • Shell state carries across commands in a session.
  • Output returns when the command finishes.
Sandbox

Restore step

Unpack a saved workspace, if there is one

Workspace container

  • Environment image
  • Picks up agent commands
  • Returns command output
  • CPU and memory limits

File helper

Signed-URL transfers

Egress proxy

When needed
/workspace · workspace disk

Repository, build outputs, installed dependencies

Kept on release and exported to a snapshot

Dashed parts appear only when needed. The disk outlives the pod: releasing a sandbox removes the pod and keeps the workspace.

When a session needs a sandbox, RMA builds one from the session's environment. An environment is a saved description of the machine the work needs: the image, CPU and memory, disk, setup steps, and network policy. For the bug-fix job, that might be an image with the project's toolchain, enough memory to run the test suite, and network access to GitHub and the package registry.

By default, the agents working together in a session share one sandbox. In the bug-fix job, the subagent that checks the regression test runs it against the same files the main agent just patched. A subagent can also get its own sandbox, or none, when its work should be kept separate.

Before creating anything, the control plane checks that the request fits on the machines we run. It then creates a disk for the workspace and a pod that uses it. RMA records which sandbox belongs to which session, so a retried step reconnects to the same sandbox instead of starting over. If the sandbox can't start, for example because its image can't be pulled or its container keeps crashing, RMA marks it failed so the session isn't left waiting.

  • Always

    Workspace container

    Runs the environment's image, with the workspace disk mounted at /workspace. A small process inside receives the agent's commands.

  • Always

    File helper

    Moves files in and out of the workspace using signed URLs.

  • When restoring

    Restore step

    Unpacks a saved workspace before the agent's first command runs.

  • When needed

    Egress proxy

    Applies the environment's network policy and can add credentials to outbound requests.

Each command the agent runs executes inside the sandbox, and its output comes back when the command finishes. Longer jobs can run in the background and write to a log the agent checks later. Shell state carries over between commands, so a cd or export in one command still applies in the next. Agents sharing a sandbox see the same files, but each session has its own shell. RMA counts commands and file transfers as activity, which comes up again below, when it decides whether a sandbox is idle.

Isolation in layers

A bug-fix agent installs the project's dependencies and runs its test suite, and either step can execute code no one on the team has read. So we assume a sandbox might misbehave and don't rely on the container alone to contain it. Like the access controls in the previous post, isolation is built in layers, each enforced in a different place:

AdmissionRestricted host accessSandbox definitions are checked before they run. Requests to share the host's processes or network, or to mount host paths outside a short allowlist, are rejected.
CredentialsKept outside where possibleFor supported integrations, RMA attaches the real credential to the request outside the workspace container, so the agent never holds it.
IdentityNo cloud permissionsSandboxes run under an identity with no permissions in our cloud environment. Files move in and out through signed URLs instead.
PlacementOrganizations kept apartSandboxes from different organizations don't run on the same node at the same time.
NetworkEnforced outside the nodeFirewall rules block sandbox nodes from connecting to other nodes and private services, apart from a few required ones. Nothing inside a sandbox can change them.
EgressSet by the environmentEach environment has no internet access, an allowlist, or open access. With an allowlist, a separate proxy filters HTTPS by hostname, and most other outbound traffic is blocked.
ManagementRestricted cluster accessThe cluster's management API has no public IP address, and access to it is authenticated.

An environment without a network policy gets no internet access. Opening it up is a deliberate choice, usually made by listing the hosts the work needs. For the bug-fix job, that's GitHub and the package registry.

These layers work together. A hostname allowlist is most effective alongside narrowly scoped credentials. And a credential passed into the sandbox as an environment variable can be read by any code running there, so where an integration supports it, choose a connection method that keeps the credential outside.

Finding capacity

When the cluster is busy, a new sandbox may have to wait. We want that to be a short wait, not a failed task. To get there, the control plane separates two cases: requests it can't serve right now, and requests it could never serve.

A request on its way to a node
  1. Admission

    Check the size

    Are CPU and memory within what our machines can serve?

  2. Queue

    Wait for a node

    A request that could fit is held by the scheduler.

  3. Scaling

    Add capacity

    If no node has room, the cluster adds one from a sandbox pool.

  4. Start

    Stream and run

    The image streams in, so the container can start early.

An impossible request fails immediately. A request that could fit waits, up to a limit.

Reject what can never fit

Each environment's CPU and memory must stay within limits our machines can serve. RMA checks this when the environment is saved, so a request that could never fit is rejected up front with a clear error, rather than waiting for a machine that won't come.

If no running machine has room, the cluster adds one from a pool sized for sandboxes, and requests waiting at the same time share it.

Wait, within a limit

A request that fits goes to the Kubernetes scheduler, which holds it until a node is ready. RMA checks on the sandbox at slightly randomized intervals, so a burst of sessions doesn't check all at once, and it stops waiting if the sandbox isn't ready in time.

Pack for bursty work

Agents use resources unevenly. A sandbox can sit nearly idle while the model is thinking, then use every core it has to compile the project. If we reserved the full requested size for every sandbox, much of each machine would go unused. Instead, a sandbox reserves less than its limit and can burst up to it. GPU sandboxes are the exception and reserve everything they ask for.

We also don't interrupt running work to save money. The autoscaler doesn't evict running sandboxes to consolidate nodes, and we don't run sandboxes on spot capacity that can be reclaimed mid-task. An agent several hours into a job keeps its machine.

Start faster

Image streaming lets a container start before its whole image has downloaded. The other slow part is usually setup: installing packages and tools. When setup can be captured as an image, later sessions start from that image and skip the installation.

When the agent goes idle

Agents spend a lot of time waiting: for a person to reply, for a scheduled wake-up, or for a build somewhere else. An idle sandbox still holds CPU and memory, so RMA releases the compute and keeps the workspace.

Say the bug-fix agent opens a draft pull request in the evening and waits for feedback. Nothing runs overnight, so its sandbox is released. When someone follows up in the morning, the agent picks up with the repository and installed dependencies where it left them.

A sandbox is released in two main ways. The first is an idle window, which each environment can configure. The second is when RMA sees that the work has paused or ended: the agent is sleeping until a scheduled wake-up, or the session was cancelled.

RMA holds off on the second kind of release when it would get in the way. A shared sandbox stays up while any agent using it is still active or a background command is still running. If the next wake-up is soon, RMA skips the release, since stopping and restoring wouldn't save anything. And a session that has just finished a turn stays up for a while, because the next thing to happen is often a follow-up from a person.

Here's what a release keeps, and what starts fresh:

Survives a release

  • Files under /workspace: the repository, build outputs, and anything the agent saved there
  • Dependencies installed under /workspace
  • Environment setup that was captured as an image

Starts fresh

  • Running processes and background commands
  • Memory, shell state, and open network connections
  • Files written outside /workspace, including /tmp
A sandbox's life after release
  1. Running

    Pod and disk are both live.

  2. Releasing

    The pod is removed.

  3. Released

    The disk is kept for a few hours and the workspace is exported.

  4. Archived

    The disk is gone. The snapshot is kept for about two weeks.

Restore from the kept disk

A new pod starts on the same disk.

Restore from the snapshot

A fresh disk is created and the snapshot is unpacked.

The agent finds the same files on either path.

Releasing a sandbox removes its pod but keeps its disk for a few hours. RMA also exports the workspace to a snapshot in object storage. The export runs in parallel so large workspaces finish sooner, and it only counts as a snapshot once every part has succeeded, so a partial export is never treated as complete.

That gives two ways back. While the disk still exists, a new pod starts on it. After the disk is gone, RMA creates a new disk and unpacks the snapshot before the agent resumes. Either way, the agent finds its files where it left them.

Snapshots last longer, about two weeks, but not forever. The workspace is for doing the work, so anything a person will need later should be saved as a deliverable.

Release shows up in cost, too. Running compute is charged while a sandbox is up, including time it spends idle, and stops once the sandbox has stopped.

Getting the most from a sandbox

A few practices follow from how sandboxes work:

  • Keep state in /workspace. Clone repositories and write intermediate results there, not in /tmp, so they survive a release.
  • Make processes easy to restart. If a task needs a dev server or a database, give the agent a command or script that starts it again after a restore.
  • Put slow installs in environment setup. Setup can be captured and reused. Steps an agent repeats in every session cost time in every session.
  • Start with a narrow network policy. Add hosts as your tasks need them.
  • Size for the heaviest step. Set CPU and memory for the build or test run, then adjust once you've seen real sessions.
  • Save deliverables explicitly. Workspaces and snapshots expire, while deliverables stay available for people to preview and download.

A workspace that waits for the agent

Most of this never shows up in a session's timeline. The agent gets a Linux machine with the tools it needs, kept apart from other organizations' work. When the cluster is busy, it waits for capacity instead of failing. And when it pauses overnight, the compute goes away while its files stay put for when it's back.

The next post in this series covers how agents in RMA improve from one session to the next.