An agent that can run code is much more useful than one that can only talk about it. It can open the spreadsheet you attached, clean it with pandas, plot the result and hand you the chart. It can also run whatever a prompt injection in that spreadsheet tells it to. So the code has to run somewhere it can do the work and very little else.
Summa gives each conversation’s agent tasks one sandbox: a Linux workspace with Python, the usual data libraries and a /workspace directory that keeps its files between turns. This essay explains the decisions behind it, and what a hosted, multi-tenant setting needed that a sandbox on a developer’s laptop doesn’t.
One note on status first. The sandbox exists only in task runs, behind the agent-tasks flag, and runs on our Kubernetes development environment. It is not deployed on the production server, because it needs a Kubernetes API and gVisor to start sandbox pods. What follows is how it works, not a claim that it is generally available.
What goes wrong with the obvious approach
We learned a lot from the coding agents. Claude Code puts an operating-system boundary around the shell commands it runs on your machine: Seatbelt on macOS, bubblewrap on Linux. Writes are limited to the working directory by default, and network traffic goes through a local proxy that checks each host against an allowlist that starts empty (Anthropic docs). The Codex CLI does something similar, with Seatbelt on macOS and bubblewrap plus seccomp on Linux, writes limited to the workspace and network off by default (OpenAI docs). Codex cloud runs tasks in isolated, OpenAI-managed containers. A setup script may reach the internet, the agent phase is offline by default, and container state is cached for up to 12 hours (OpenAI docs).
Those are good designs for what they protect: one person’s machine, or a short-lived container for one task. Copying either straight into Summa would have missed three things.
- The machine is ours, and it is shared. A local sandbox protects the user’s laptop from the agent. A hosted one has to protect every tenant from every other tenant, and the cluster from all of them.
- A conversation outlives a pod. People come back to a conversation the next day and expect the cleaned file to still be there. Keeping a pod running for days is expensive. Throwing it away loses the work.
- Nobody approves each command. A task run works in the background. There is no person at a prompt to say yes to a network call, so the boundary has to hold without one.
One sandbox, named by a hash
The backend never tells the controller which tenant or conversation a sandbox belongs to. It sends a name derived from both:
def workspace_id(tenant_id: uuid.UUID, conversation_id: uuid.UUID) -> str:
return hashlib.sha256(f"{tenant_id}:{conversation_id}".encode()).hexdigest()
The controller accepts only a 64-character lowercase hex string in that position. A conversation id that leaks, or is guessed, is not enough to reach a sandbox, because the name also depends on the tenant. And the controller has nothing to look up: there is no list of tenants for a bug to get wrong.
The controller itself is private. It requires a bearer key of at least 32 characters, and a network policy admits only the backend and the agent worker. It is also the only thing with rights over the summa-sandbox namespace. Its role there allows creating, reading, listing, patching, exec-ing into and deleting pods, and nothing else. The backend and worker call the controller. They never call Kubernetes.
Hibernate to object storage, never overwrite with nothing
A sandbox pod is created on first use and reused across tool calls. After 30 minutes without an operation, or 8 hours in total, the controller’s reaper saves /workspace as sandboxes/<workspace_id>.tar.gz in a private bucket and deletes the pod. The next tool call in that conversation creates a new pod and unpacks the archive into it. Files survive, and so do packages, because pip install lands in /workspace/.local.
The dangerous moment is the restore. If unpacking fails and the new pod carries on empty, the reaper will later archive that empty workspace over the saved one, and the work is gone for good. So a failed restore deletes the new pod and returns workspace_restore_failed, telling the model to try again shortly. The code comment is one line: “An empty sandbox would later be archived over the saved one.”
Two more rules keep archives honest:
- A size cap. An archive over 512 MiB compressed is not saved. Its older archive is then deleted too, because restoring it would bring back a silently stale workspace.
- The model is told. When a sandbox started empty, with nothing restored, the tool result starts with a note saying so. The model doesn’t assume files that aren’t there.
Unpacking uses Python’s tarfile with filter='data', which refuses members that would land outside /workspace, links that point outside it and device files. Deletion is strict as well. When a conversation is removed by data retention, a temporary chat expiring or a user’s erasure request, the backend deletes the sandbox and its archive first. If the pod can’t be deleted, the call fails rather than leaving a pod that the reaper would archive again.
Conversation data stays out of the pod spec
The easy way to run a command in a pod is to put it in the exec arguments. In Kubernetes, those arguments can show up in API server audit records. A pod spec is stored in etcd. Neither is a place for a user’s command, file name or file contents.
So the exec arguments never change. Every operation runs the same static script under python -I -B, with one argument: the length of the request. The request itself, as JSON, arrives on stdin, and any file bytes follow it raw. The script reads exactly that many bytes for the request and uses a bounded reader for the rest. File paths are resolved inside the pod and refused if they leave /workspace.
The same thinking applies one level up. When the backend uploads a file, the path travels in a header, never in a URL that an access log would record.
Files move as bytes, checked at every hop
Files first crossed as whole base64 inside JSON, and again through the exec stream. The commit that replaced this counted about six copies in memory, which is why the limit was 25 MB. Now they stream as raw bytes. An imported document goes from the object store through the backend to the controller, which spools it to disk. It must match its declared length and SHA-256 before it uses a slot in the sandbox. Inside the pod, the bytes are written to a staged .incoming- file next to the target, hashed again, and renamed into place only if the digest matches. A cut-off or altered transfer never leaves half a file where the agent expects a whole one.
For imports, the expected digest is the one recorded when the user uploaded the file and it was scanned. What the agent opens is byte for byte what the user attached. Reads work the same way in reverse, with the digest in a header and checked again by the backend. The import limit is now 100 MB, the same as uploads.
A pod that can do very little
Each sandbox is a pod with almost no powers:
- It runs under gVisor, on a dedicated node pool that is tainted so nothing else is scheduled there. A kernel escape from model-written code lands on a node that runs only other sandboxes.
- It runs as user 1000 with a read-only root filesystem, all Linux capabilities dropped, no privilege escalation and the runtime-default seccomp profile. The namespace enforces the Kubernetes Restricted Pod Security profile.
- It has no service-account token, no secrets, no service links and no persistent volume.
/workspaceis a 1 GiB scratch volume and/tmplives in memory. - Memory is capped at 1 GiB and CPU at one core. A quota allows eight sandboxes at once. When it is full, the model gets
workspace_capacityand a message to try again in a few minutes, instead of a cluster error.
The network starts from default-deny for both ingress and egress. Sandbox pods may reach DNS and one Squid proxy, nothing else. Squid allows CONNECT on port 443 to pypi.org and files.pythonhosted.org, and refuses every private and internal address range whatever DNS says. A network policy keeps the proxy itself off private ranges, in case that rule ever failed. So pip install works and nothing else reaches the internet.
A command ends when it ends
A sandbox that lives for hours invites a quieter problem: a process that keeps running after its command has finished. Each command runs in its own session. When it exits or hits its time limit, at most 600 seconds, the whole process group is killed. A background server, a stray & or a forked worker doesn’t outlive the call. If the caller hangs up, because the run was stopped, the stream closes and the script kills the command rather than leaving it to hold the sandbox’s CPU.
Results are treated with suspicion too. Commands run with pipefail, after python analysis.py 2>&1 | head reported success while the script had crashed. If the pod never reports an exit status, the operation fails with exit_status_missing. A process killed before it could report, or a lost connection, is not success. Output is capped at 32 KB, keeping the start and the end, because the end of a log is where the traceback is.
Files in and out go through the front door
The sandbox is not a side entrance to the user’s documents. import_file accepts only a document ref, such as doc1, that this run was given by list_documents or search_attachments. On every call it looks the file up again under the run’s own scope and checks access, so a ref proves the file was shown to the run, not that it is still readable. It also needs the knowledge.read grant.
export_file hands a sandbox file to the user through the same path as any other generated file: the per-run file quota, the size limit and a ClamAV scan before it is marked ready. File types outside documents, spreadsheets, text, images, audio, video and archives are refused, so an executable has to be zipped before it can be shared.
What it costs
- Cold starts. A conversation that has been idle starts a pod and restores its archive on the next call. Each tool’s timeout budgets 360 seconds for that, on top of its own work.
- A failed restore blocks work. We chose to refuse rather than continue empty. If the object store is unreachable, the agent waits instead of starting fresh.
- Large workspaces aren’t kept. Over 512 MiB compressed, the workspace is gone when the pod is reaped. The model is told the next sandbox started empty. The user may not be.
- Capacity is finite. Eight sandboxes at once is a real limit, and a full quota means waiting.
- One package registry. PyPI works. npm, GitHub and arbitrary downloads don’t.
- Not in production. All of this needs Kubernetes and gVisor. The production server has neither, so production runs without agent tasks.
What we would generalise
- Derive names, don’t trust them. If an internal service addresses tenant data, give it a name that already contains the tenant, so a wrong lookup can’t cross over.
- Never let nothing overwrite something. A restore that fails should fail loudly and remove the empty copy, before anything can save it over the real one.
- Keep user data out of control-plane records. Pod specs, exec arguments, URLs and logs outlive the operation. Put content on a stream instead.
- Check the digest where the file lands. Checking at the start of a pipeline proves nothing about the end. Stage, verify, then rename.
- Treat silence as failure. A missing exit code, a cut stream or a missing archive should never read as success.
- The sandbox borrows the run’s authority. Getting files in and out should go through the same refs, scans and quotas as everything else, so the sandbox never becomes a second, weaker path.