Fran Marcano
Agent layer, back to the systems

Building agents · Architecture · 7 min read

How I build agents, and the harness that keeps them in bounds

I build production agents and the harness around them. Subagents get a context of their own, nothing the model must not hold comes within its reach, memory has a budget, and evals decide which changes stay.

Delegation
Specialists · forks with a clean context
Containment
Key outside the sandbox · egress fails closed
Evals
Held-out cases · pass^k
Contents

These patterns come from two systems I run. One is an internal agent that engineers reach from their team chat, with company accounts and roles, next to the company's production. The other is FlyWorkers, my own product, where agents work unattended for customers, run whatever code they decide to run and read pages written by strangers. Most of what follows holds for both. Where it doesn't, the difference explains the design.

Delegation

Two ways to delegate

An agent that carries every tool and every instruction gets worse at each job as the list grows. Delegation splits the work, and it comes in two shapes that solve different problems.

Specialists. An orchestrator receives the request and hands specialized work to subagents, each with its own prompt, its own tools and its own evals: test automation, triage of support requests and crash alerts, SRE support during an incident. A narrower tool set is also a smaller blast radius, and each specialist's score moves on its own. The orchestrator I run this way is built with the Strands Agents SDK on AWS Bedrock AgentCore. In front of it, a gateway that holds no model receives the chat event and picks the system prompt for the channel, so I can try a prompt change with one HTTP call and no chat at all. Not every job needs the orchestrator, either. When a test management service already knows the scenario, phone and build for a job, it calls the test automation specialist directly, since a general agent in that path would only add a model call.

Forks with a clean context. Here an agent delegates to itself. A delegate_task tool runs a child turn in the same harness process, with the same identity, sandbox and key. The child inherits the parent's system prompt plus a short section at the end that says it is a subagent; at the end, so the parent's prompt stays an exact prefix and the prompt cache still applies. It gets the task and whatever context the parent writes, never the parent's conversation, and it cannot delegate again. What the fork buys is context: reading ten files to answer a one-line question doesn't fill the parent's.

Forks are where spend gets away. My first version gave a child at most half of what the parent had left, with no floor. That half could be almost nothing, and each child still paid for a full iteration before the cap stopped it. Measured, a turn with four subagents spent 7.8 times its ceiling. Now a child runs only if its half covers what the parent's last iteration cost, and the bound is one the design can promise: one extra iteration for the parent, plus one per child in flight.

Two ways to delegate

Specialists with their own tools, or a fork with a clean context

Fig. 1: who receives a request, who reasons about it, and where a subagent runs, in each shape. Left, specialists. A mention in the team chat goes to a gateway that holds no model and looks up the channel and its prompt. The gateway sends the orchestrator the prompt, asker and thread. The orchestrator delegates to three specialists, each with its own prompt, tools and evals: test automation, triage and SRE support. A test management service sends one job straight to the test automation specialist, past the gateway and the orchestrator. The orchestrator returns its answer to the gateway, which posts it in the team chat. Right, a fork. A request sends the harness the full conversation. Inside the harness, the agent turn calls delegate_task with a task and context, and a child turn runs nested inside it, at depth 1, with half of what's left to spend, if that covers an iteration. The child turn returns a report, marked untrusted. The harness returns the answer to the request. Specialists Fork Team chat Gateway NO MODEL channelprompt Orchestrator Test automation Triage SRE support own prompt, tools, evals Test management service Request Harness Agent turn Child turn DEPTH 1 half of what's left, if it covers an iteration mention prompt, asker, thread delegates one job answer posts full conversation delegate_task(task, context) report, marked untrusted answer Fig. 1: the two ways to delegate, specialists on top and a fork below. Specialists. A mention in the team chat goes to a gateway that holds no model: channel and prompt. The gateway sends the orchestrator the prompt, asker and thread, and gets back the answer, which it posts in the team chat. The orchestrator delegates to three specialists, each with its own prompt, tools and evals: triage, SRE support and test automation. A test management service sends one job straight to the test automation specialist. A fork. A request sends the harness the full conversation and gets the answer back. Inside the harness, the agent turn calls delegate_task with a task and context; the child turn runs nested inside it, at depth 1, with half of what's left to spend, if that covers an iteration, and returns a report, marked untrusted. Specialists Team chat Gateway NO MODEL channel · prompt Orchestrator Triage SRE support Test automation own prompt, tools, evals Test management service Fork Request Harness Agent turn Child turn DEPTH 1 half of what's left, if it covers an iteration mention posts prompt, asker, thread answer delegates one job full conversation answer delegate_task(task, context) report, marked untrusted
Fig. 1A specialist brings its own tools and its own score. A fork brings a clean context and a share of the budget.

Boundaries

Containment: what the agent can reach

An agent that can run code will, sooner or later, run code it shouldn't. So I design what it can reach rather than what it is told: the model's credentials, the integrations' tokens, the network, other tenants and production.

Credentials stay outside the sandbox. Each agent works in a sandbox container of its own. The harness, pi embedded through its SDK behind an interface of my own, runs beside it in the same VM and holds the model key in RAM for the length of a turn, never on disk. Every tool the agent calls runs inside the sandbox through docker exec, so the agent can run anything there and still has no way to read the key: the process that holds it isn't there. In the first plan the harness ran inside the sandbox, where an agent with a shell could read the memory of the process next to it. A review caught it before any code existed, and I didn't build on the new topology until a spike proved it. A sentinel shaped like an API key went into the harness's environment, and 33 assertions passed: it was absent from the sandbox's environment, from every process's environment and command line, from the container's configuration and from every file in its root filesystem, and the sandbox couldn't reach the harness by any route tried. A positive control made sure a sentinel that was never exported couldn't pass for the wrong reason.

Integrations follow the same line. The harness calls a remote MCP server itself, with the token from the agent's vault in a header, so the token never enters the container. A local MCP server, like Playwright's test server, has to run next to the code it works on, so it runs inside the sandbox as one of the agent's own processes, never in the harness beside the key.

The network fails closed. Traffic leaves the sandbox only through an egress proxy, and a proxy that doesn't know its policy answers 503 to everything. A per-agent domain allowlist was the default until I opened egress, because an agent meant to work like a person at a screen can't ask for permission per domain; the allowlist stayed as an option. What stays closed is the infrastructure underneath: private ranges, loopback and the cloud's metadata endpoint are refused even with egress open.

Without a sandbox, the bounds go into the tools. An agent that serves colleagues instead of running untrusted code still needs limits, and there they are code around the model. Tools are typed, and some are served by MCP servers I built behind company SSO (OIDC). Each action is checked against the engineer's role, and the infrastructure tools are read-only and refuse production before they call anything.

Containment by design

What an agent can reach inside one customer's VM, and what it can't

Fig. 2: the trust boundaries around an agent, and the only paths that cross them. A customer VM holds two zones with a boundary between them. In the trusted zone, the harness holds the key in RAM: pi, the model loop, the MCP client and the vault tokens. In the untrusted zone, the sandbox, one per agent, holds the workspace, the tools, the memory volume and the local MCP servers. The harness runs the tools in the sandbox through docker exec. From the sandbox there is no route to the harness: a dashed line stops at a barrier, and the spike checked it with 33 assertions. Outside the VM, the harness calls the model provider with the key in a header and a remote MCP server with the token in a header. All of the sandbox's traffic goes to the egress proxy, which fails closed and passes public destinations to the internet; a dashed line toward private ranges, loopback and metadata stops at a barrier. Another customer's VM, outside, has a dashed line toward the harness that stops at a barrier: the tenant boundary. Customer VM Trusted zone Untrusted zone Harness KEY IN RAM pimodel loop MCP clientvault tokens Sandbox ONE PER AGENT workspacetools memoryvolumelocal MCP servers Model provider Remote MCP server Egress proxy FAILS CLOSED Internet Another customer's VM docker exec (tools run here) key in header token in header all traffic public destinations private ranges, loopback, metadata no route (spike: 33 assertions) tenant boundary Fig. 2: one customer VM, the trusted zone on top and the sandbox below, with the proxy and the outside world under it and another customer's VM last. Above the VM, outside it: the model provider, which the harness calls with the key in a header, and a remote MCP server, which it calls with the token in a header. In the VM's trusted zone, the harness holds the key in RAM: pi, the model loop, the MCP client, the vault tokens. A boundary separates it from the untrusted zone below. The harness runs tools in the sandbox through docker exec; from the sandbox there is no route back to the harness, a dashed line ending at a barrier, checked by the spike with 33 assertions. The sandbox, one per agent, holds the workspace, the tools, the memory volume and the local MCP servers. Below the VM, all of the sandbox's traffic goes to the egress proxy, which fails closed and passes public destinations to the internet; a dashed line toward private ranges, loopback and metadata ends at a barrier. Last, another customer's VM: its dashed line toward this VM's harness ends at a barrier, the tenant boundary. Model provider Remote MCP server Customer VM Trusted zone Harness KEY IN RAM pimodel loop MCP clientvault tokens Untrusted zone Sandbox ONE PER AGENT workspacetools memory volumelocal MCP servers Egress proxy FAILS CLOSED Internet Another customer's VM key in header token in header docker exec (tools run here) no route (spike: 33 assertions) all traffic public destinations private ranges, loopback, metadata tenant boundary
Fig. 2The agent can run anything in its sandbox. The key, the tokens, the infrastructure underneath and the other customers stay out of its reach.

Memory

Memory with a budget

Whatever enters the context is paid for again on every turn after it, so memory enters when the agent asks for it, in bounded amounts.

Within a conversation, the thread is the memory: a follow-up keeps what came before, and documentation enters only through a search, over pgvector.

Across conversations, I don't rely on the model to take notes. An agent told in its prompt to write them before ending a turn didn't, in production, and its memory volume stayed empty after turns with real work. So the harness writes a session journal itself after every turn, into the agent's own volume: the user's last message, the final answer and one line per tool call, each with a size cap, with caps on each file and on the whole directory. The journal never enters the prompt on its own. The agent searches it with recall, a literal-text search that runs inside the sandbox, and the matches come back marked as untrusted text. After a turn that used tools, the harness also asks the agent whether it learned something it couldn't work out again, and gives it up to three tool calls to save it, inside the turn's spend.

Skills follow the same rule. The prompt carries only an index of them, with name, description and path, never their bodies, and the agent opens a skill when the work calls for it.

Evals

Evals decide what stays

A prompt edit that fixes one transcript can quietly break three others, so a change to a prompt, a tool, the harness or a playbook doesn't stay because it reads better. It stays if it scores higher.

The cases come from real tasks and from production failures, and each failure becomes a new case. Deterministic checks grade what can be checked exactly, and an LLM-as-judge grades the rest, calibrated against grades a person gave. A case counts only if all k runs pass (pass^k), since an agent that answers a support thread correctly most of the time still gets some threads wrong. And a change has to win on cases held out from tuning, because a prompt tuned on the cases it is measured on learns those cases.

For a new agent role, the evals come before the prompt. They are iterated against until the score stops rising, and every iteration is recorded with its transcript, so a regression shows up as a diff of scores. A Quality Engineer role has twelve cases, from a credential pasted in the chat to production offered as the test environment and a sleep proposed as the fix for a flaky test. It reached 12 of 12, then 11 of 12 twice with the failure moving between soft criteria, which is the model and the judge varying, not a rule left to write.

Safety properties aren't left to evals. They are tested as code, and the tests are checked by mutation: removing the proxy's fail-closed default turns a test red.

Retrospective

What I got wrong about tenant isolation

I chose one VM per customer so that an agent escaping its container would reach only agents of the same customer. The threat model said so: a compromised harness meant root on that customer's VM, and nothing across tenants.

Reading the deployment against that sentence showed it was false on the network. Every customer VM was an app in the same Fly organization, Fly's private network spans the whole organization, and the harness listened on that network with no authentication. The egress proxy blocked those addresses from inside the sandbox. But the sandbox runs on runc, and an agent that escaped its container in customer A's VM could reach customer B's harness with a single HTTP request. From there it could cancel B's turns, watch B's live browser view, or run turns on B's VM with B's memory mounted. The VMs separated the kernels, and nothing separated the harnesses.

The fix is a random 32-byte token per customer. The provisioner generates it when it creates the VM and stores it as a secret of that VM's app before the machine starts. The VM moves it to a file only its owner can read and removes it from the environment. The harness refuses to start without it and requires it on every route except the health check, compared in constant time. The control plane sends it from a single function on all seven paths it uses to reach a harness. An escape in A's VM now yields A's token, which works only in A.

I considered a private network per customer, but the control plane has to reach every VM and a machine belongs to only one network. Mutual TLS would also authenticate the control plane to the VM, at the price of a certificate authority and certificates for every VM; it stays the option if a second legitimate caller ever appears. One token shared by every VM would close the path from the sandbox and leave the path between customers open.

The mistake was treating a deployment decision as a security property without checking the deployment. The threat model now names what separates customers on the network, and removing the check turns tests red.

Related

Two specialists in detail

Agentic test automation covers the test automation specialist: how a scenario written in plain language becomes reviewed test code on a real phone, and why every run after that is plain code.

Triage agent covers the triage and SRE specialist: how a crash alert or a support request gets a first answer in its thread, built from the company's telemetry and the errors the team has already diagnosed.

Next system

Who writes the end-to-end tests?

An engineer describes a flow in plain language. The agent drives a real phone or a browser and writes the test. After that, the test replays the same steps every time, with no model in the run.

Device layer

Contact

What should your team stop doing by hand?

LinkedIn