DEV Community

Cover image for Should you split your agent's brain from its hands?
Elia Secchi for Google Cloud

Posted on Edited on Originally published at eliasecchig.github.io

Should you split your agent's brain from its hands?

Code has become the universal tool for AI agents. Instead of building a custom tool for every task, you give an agent a shell so it can write and run its own scripts. That leaves you with two distinct parts: the brain is the loop that calls the model, and the hands are the shell and workspace where commands run and files live.

Giving an agent a shell makes it far more capable, and also dangerous. Anything the agent reads (a webpage, a file, or a tool output) can talk it into running commands you never approved. A system prompt won't reliably stop that, because a prompt is a set of instructions, not a security boundary. Real safety has to live in the infrastructure, starting with locking those hands inside an isolated sandbox.

Once you draw that boundary around the hands, one architecture question shapes your design: should the agent loop run within the sandbox or outside of it? In other words, should the brain stay outside the sandbox, or live inside with its hands? On request-based runtimes like Cloud Run, the brain runs outside, so your orchestration stays separate from untrusted code and scales on its own, with tool calls reaching a remote sandbox over the network. On stateful sandbox runtimes like Agent Substrate 1.0, which runs on Kubernetes and scales to millions without idle VMs, brain and hands share one sandbox, so tool calls stay local without giving up isolation. Choosing between them comes down to whether your orchestration needs a life of its own.

Coupled vs. decoupled harnesses

To answer that, start with how a harness runs before you split anything. Alongside the brain and hands, any multi-turn agent keeps a third piece, session state (its conversation history and event log). On your laptop, all three live on one machine, and one turn passes between them in three steps:

  1. You send a task. The brain loads the session history and sends it to the model with your new message.
  2. The model answers with a tool call, such as a shell command to run or a file to edit. The brain passes the call to the hands on the same machine, and the hands run the command, change files, or start a background process.
  3. The output comes straight back to the brain. The brain appends the tool call and its result to the session, then calls the model again.

Steps 2 and 3 repeat until the model returns a final answer. Every hand-off is local, so only the model call leaves the machine.

A stick figure labeled you points with an arrow labeled 1. task into a dashed box labeled your laptop (one machine) that holds a brain box, a hands box, and a session cylinder; a two-way arrow labeled model calls connects the brain to a model box outside, an arrow labeled 2. local call connects brain and hands, and an arrow labeled 3. save step goes from brain to session.

Figure 1. On your laptop, brain, hands, and session share one machine, so only model calls leave it.

In production, those same three steps run on every turn, and you can build them with two different architectures:

  • Coupled (one machine per agent): you keep the laptop model and give each agent its own isolated box in the cloud. Brain and hands stay inside the same sandbox, so every tool call is local. When the agent waits, a stateful sandbox runtime like Agent Substrate 1.0 (which calls that box an actor) snapshots its memory and files and wakes it on the next message.
  • Decoupled (a microservice architecture): you split the harness into a web service, a database, and a remote sandbox. The brain runs on a request-based runtime like Cloud Run (where any running copy of your service can answer the next request), sessions live in an external database, and every command to the hands crosses the network.

At a high level, the distinction is whether you treat each agent as its own suspendable machine, or run the brain as a web service that drives remote hands. Think of a coupled harness a bit like a workshop with a desk inside it, where you lock the door when you step away and find your tools where you left them, and a decoupled harness like a dispatch desk that calls out to separate workshops only when a job needs tools. Every trade-off that follows comes from that choice.

Pros and cons of decoupling

We'll start with the decoupled layout, where the brain runs outside the sandbox on a request-based runtime like Cloud Run.

A stick figure labeled user points to a box labeled brain (Cloud Run) with an arrow labeled HTTPS requests, and the brain points to a box labeled hands (sandbox) with an arrow labeled remote tool calls and to a cylinder labeled sessions and task store with an arrow labeled save state.

Figure 2. In a decoupled harness, the brain on a request-based runtime (such as Cloud Run) reaches its hands and session state over the network.

In Figure 2, each of the three laptop steps now crosses a network:

  • Your task arrives at the brain over HTTPS requests.
  • The brain sends each command as a remote tool call to the sandbox and waits for the output.
  • The brain writes each tool call and result to the database (save state) so any instance can load it next.

Pros

On a request-based runtime like Cloud Run, decoupling gives you five strengths:

  1. Guardrails, approvals, and core credentials sit out of reach of generated code. Tool allowlists, spend caps, approval gates, and the audit log run in the brain's process, where an injected shell command can't tamper with them. Model and platform keys stay there too. The remote sandbox can still block outbound traffic by default, and an egress gateway (its single exit) adds tool credentials outside it.
  2. Tools that don't need a sandbox run on the brain, with their own path to the outside world. You can give the agent web search or internal company APIs there and keep the sandbox locked down.
  3. Waiting on the model is cheap, and plain chat or API turns never wake a sandbox. A single brain instance can hold many slow model calls at once (Cloud Run, for example, allows up to 1,000 concurrent requests per instance), while turns that skip shell or file tools never touch a sandbox.
  4. One brain can drive many disposable sandboxes, each sized for its job. You can run subagents in parallel, give a heavy tool more CPU, memory, or a GPU, and throw away a compromised sandbox without losing the session.
  5. Sessions live in an external database, and a brain upgrade is a rolling deploy. Offline evaluations and background jobs read that database without waking a sandbox, and a new brain version ships with traffic splitting and rollback.

Cons

Decoupling costs you four things:

  1. Two sources of truth can drift apart, because the session database and the sandbox's files are never saved in one step. After a crash during a tool call or a recycled sandbox, you need idempotent tools (safe to run twice) or a step that reconciles the two.
  2. Remote tools add latency, and a laptop harness needs changes before it runs here. Hundreds of file reads become hundreds of network round trips, and interactive terminals need a custom remote protocol.
  3. One brain process serves every user. It reads untrusted tool output while it holds core credentials, so brain-side tools need tight per-user authorization and allowlists.
  4. Long turns need their own durability and deploy handling. Request-based runtimes are built for requests that start and finish, and on Cloud Run a rollout sends SIGTERM (a shutdown signal) with a 10-second grace period.

Example: Long Horizon on Cloud Run

The public Long Horizon recipe in google/adk-recipes is a decoupled harness on Cloud Run built for long turns:

  • The brain is a FastAPI web app with an Agent Development Kit (ADK) runner on Cloud Run.
  • Sessions sit in Cloud SQL, a managed database, through ADK's DatabaseSessionService in the recipe's Terraform deployment.
  • Long-term memory across conversations lives in Memory Bank, where a nightly job consolidates it without waking any sandbox.
  • The hands run in one sandbox per person, built from the recipe's own container image.

Picture a long turn on a default Cloud Run service before those settings are tuned. A person starts a task in their browser, and it runs past Cloud Run's default request timeout of 5 minutes, so Cloud Run closes the stream with an HTTP 504 error. If the person closes the tab while the agent keeps working, the turn has no open request attached. When they reconnect later, any instance can answer that new request, so the client has to find the work still in flight and catch up on missed events.

The table puts that long turn beside what each runtime category does.

Request-based runtime (e.g. Cloud Run) Long-horizon turn Stateful actor (e.g. Agent Substrate)
Requests finish within a configured timeout (5 minutes by default, up to 60 on Cloud Run). It keeps running after its connection closes. The turn runs as a process inside the actor, with no single HTTP request to outlive.
Any instance can answer the next request, and session affinity is best effort. A returning client has to find the work still in flight. Every request names its actor, so a reconnect goes back to it.
State lives in an external database. It builds up working memory, files, and running processes. A suspend saves memory, files, and processes, and a wake restores them.

Cloud Run settings for hour-long turns

To keep a long turn running across timeouts and disconnects, Long Horizon gives Cloud Run four settings in Terraform (its infrastructure as code). List them from a google/adk-recipes clone:

$ grep -nE "^ +(timeout|session_affinity|min_instance_count|cpu_idle)" \
  core/python/long-horizon-harness/terraform/cloud_run.tf
18:    timeout = "3600s"
22:    session_affinity = true
37:      min_instance_count = 1
64:        cpu_idle = false
Enter fullscreen mode Exit fullscreen mode

Each setting protects one moment of that long turn:

  1. timeout = "3600s" raises the limit from 5 minutes to the 60-minute maximum, so the stream stays open mid-task.
  2. session_affinity = true steers a reconnecting client back to the instance running its turn.
  3. min_instance_count = 1 keeps one warm instance up when traffic is light, so the service doesn't scale to zero mid-turn.
  4. cpu_idle = false leaves CPU allocated after the tab closes, so the turn keeps running.

Session affinity is best effort, so Long Horizon also writes task events to a DatabaseTaskStore on Cloud SQL. A returning client reads any missed events from that store, whichever instance answers.

Pros and cons of keeping them coupled

Now flip the design around and move the brain back inside the sandbox. A coupled harness runs on a stateful sandbox runtime, which separates each workspace from the machine under it. For example, Agent Substrate 1.0 suspends an idle actor to local disk and Cloud Storage and wakes it in under a second.

A box labeled your app points to a router, which points to a large box labeled actor sandbox that holds a brain box and a hands box side by side, with a down arrow labeled suspend and an up arrow labeled wake under 1 s to a bucket labeled Cloud Storage, an arrow labeled no keys inside to an egress gateway, and an arrow labeled adds keys from the gateway to model and tools.

Figure 3. Brain and hands share one actor, and the egress gateway adds keys outside it.

Pros

Keeping brain and hands in one box gives you four strengths:

  1. Tool calls stay local, and development matches production. The container from your laptop runs in production without SDK changes, with ADK, Google Antigravity, or any other agent framework or harness. Dev servers, interactive terminals, and language servers stay alive across turns.
  2. Working memory, files, and running processes are saved together in one atomic snapshot, so they can't drift apart. On Agent Substrate 1.0, you can rewind a crashed actor to its last snapshot, or fork a snapshot to branch a whole agent and its workspace for evaluations or bug reproduction.
  3. Each person's brain is isolated too, in its own gVisor sandbox or Cloud Hypervisor microVM (a lightweight virtual machine). Keys stay outside here too, because outbound traffic is blocked by default and the egress gateway adds model and tool credentials on the way out.
  4. Waiting between turns and at human approval gates is cheap. A suspended actor frees its slot on a warm worker, so hours of waiting on a person cost only storage. A new actor starts from a golden snapshot (the pre-initialized state of your harness).

Let's trace one turn across Figure 3, from left to right:

  1. Your app sends the message to the router and names the actor, so the router delivers it to that person's sandbox.
  2. Inside the actor, brain and hands run the laptop loop, and calls to the model or a tool's API leave through the egress gateway.
  3. The person closes the tab, and the turn keeps running as a process inside the actor. A reconnect names the same actor, so the router sends it back there.
  4. Once the turn ends, your app calls SuspendActor, and the actor's memory and files go down the "suspend" arrow to Cloud Storage.

Cons

You might ask whether local tool calls and sub-second wakes make one box the right choice for every agent, and they don't, because one box costs you five things:

  1. The harness shares its box with generated code. Keys stay behind the egress gateway, but an injected command can still reach harness files, prompts, and local logs. Put hard gates outside the box (egress policy and approvals in your app), and stream events to an external append-only log.
  2. You pay for the full sandbox while the model thinks, because an active actor holds its worker slot and RAM until the model's stream finishes. One box wins between turns, and a decoupled brain wins during slow model calls.
  3. Upgrading a sleeping fleet means cold boots. On Agent Substrate 1.0, a suspended actor that moves to a new template (its image and compute settings) keeps only the data on its volumes, so the next wake boots fresh. Keep durable state on volumes and build the harness to restart cleanly.
  4. Brain and hands share one compute shape and serve one session at a time. You can't size a lightweight loop separately from a memory-hungry or GPU-heavy tool (Agent Substrate 1.0, for example, has no GPU passthrough), and each actor serves one person rather than pooling many shared callers behind one API.
  5. Suspending drops live connections, and your app owns suspend timing. Pausing a box closes open client streams, database pools, and Model Context Protocol (MCP) sessions, so clients and harnesses must reconnect on wake. Your app also decides when it is safe to suspend so an unattended turn isn't paused mid-work.

How to choose: brain only, one box, or decoupled

With both layouts on the table, how do you pick one? First check whether your agent needs hands at all, which gives you the three shapes in Figure 4.

A decision flow that starts at a diamond labeled Needs files or processes?, where no leads to Cloud Run (brain only) and yes leads to a second diamond labeled Any of the 4 signs below?, where yes leads to Decoupled (Cloud Run + sandbox) and no leads to One box (Agent Substrate).

Figure 4. Two questions sort an agent into brain only on a request-based runtime, a decoupled harness, or one box on a stateful sandbox runtime.

Question 1 asks whether your agent needs files or processes. If its tools are plain API calls and its state lives in a database, run the brain alone on a request-based runtime like Cloud Run. If it runs a shell, writes files, or keeps processes alive between tool calls, move on to question 2.

Question 2 asks whether any of these four signs is true for your agent:

  1. Most of your turns skip sandbox tools, so a decoupled brain answers plain chat and API calls without waking the sandbox.
  2. Your sessions and memory must stay readable, searchable, or available to background jobs without waking every sandbox, as with Long Horizon's nightly memory consolidation.
  3. Many clients or channels share one stateless service API, as Long Horizon's brain does for its web frontend, a scheduler, and other agents.
  4. Your guardrails, approvals, or brain-side tools need their own trust boundary or release cycle, as when the brain runs web search and the sandbox stays locked down.

Sign 1 is really about idle time, and agents have two kinds of it. While the model thinks, a decoupled brain costs less, because only the small brain service is working and the full sandbox does nothing. Between turns and while a turn waits for approval, one box costs less, because the whole agent suspends in one piece.

So, should the brain stay outside the sandbox or live inside with its hands? If at least one sign is true, your orchestration needs a life of its own. Keep the brain outside on a request-based runtime like Cloud Run and have it drive a remote sandbox, as Long Horizon does. If no sign is true, put the brain inside with its hands on a stateful sandbox runtime like Agent Substrate 1.0. For long-horizon harnesses that live in a workspace, this gives you far fewer moving parts in your application code. Tool calls stay local, one atomic snapshot saves the whole agent, and you have no timeout or task-store plumbing to maintain.

What to take away

  • Match the runtime to the workspace. Skip the sandbox on a request-based runtime like Cloud Run for API-only agents, keep brain and hands coupled in one box for workspace-heavy long-horizon harnesses, and decouple when your orchestration needs a life of its own.
  • Decide where your guardrails live, because a decoupled brain keeps approvals, spend caps, and logs away from generated code, while one box needs those gates outside the sandbox.
  • Count two kinds of idle time, since a decoupled brain costs less while the model thinks and one box costs less between turns.
  • Plan upgrades and state consistency up front, with idempotent tools for a decoupled harness and durable state on volumes for one box.

Try it

Top comments (10)

Collapse
 
max_quimby profile image
Max Quimby •

The brain/hands framing is clean, and the security point underneath it is the one that matters most: a system prompt is not a boundary. We treat anything the hands read — a web page, a tool result, a file — as hostile input to the brain, because that's exactly the injection path, and no amount of "do not run destructive commands" in the prompt closes it.

On coupled vs decoupled, the deciding factor for us wasn't scaling — it was blast radius and observability. Decoupled (brain outside, hands in a remote sandbox) means every tool call crosses a network boundary you can log, rate-limit, and kill independently of the orchestration loop. That seam is annoying for latency but priceless when an agent misbehaves and you want to sever the hands without tearing down the whole session's state. Coupled is simpler and local until the day you need to forensically answer "what did it actually run," and then the shared sandbox makes that harder. How are you handling session-state durability when the brain lives inside an ephemeral sandbox that can get reaped?

Collapse
 
kami_butt_69b922ade8de012 profile image
Agentic Affairs •

The load-bearing point is that guardrails, approvals and core credentials sit out of reach of generated code in the decoupled layout — a system prompt is instructions, not a security boundary, and this makes that concrete. The trade-off I'd push on is the network hop per tool call: every command to the hands crosses the wire, plus a state save each turn. At what call volume does that overhead make the coupled layout win, or does the sandbox locality of Agent Substrate make it a non-issue in practice?

Collapse
 
heyvaldemar profile image
Vladimir Mikhalev •

The brain's own output is an exit too. Across 168 triages in 56 runs of a Cypress triage agent (42501583888 to 46459395874), a note planted in a failed test got granite-4.0-1b to act on it 12 times and qwen3.5-2b 9 times, almost always by putting a data link into the summary the brain posts to Slack.

That summary goes through a notifier that breaks links and mentions and turns previews off, so the link lands dead. An allowlist in the brain covers what it calls. It also has to cover what it says.

Do the guardrails you put on the Cloud Run side filter the final answer, or only the tool calls?

Collapse
 
gautamtalksdev profile image
Gautam K •

Splitting the brain from the hands makes a lot of sense, mostly because the hands are where the damage happens. If the shell runs somewhere separate with its own narrow credentials, a confused brain can only do so much. Do you keep the approval for risky commands on the hands side too?

Collapse
 
sandscale profile image
Sandscale •

Clear framing, and the "a prompt is not a security boundary" line is the right place to start. One thing I'd add to the decoupled column: once the brain holds the model keys and the hands hold nothing, the sandbox's egress policy becomes the main lever, because an injected command can still try to send workspace files out. Default-deny outbound plus the egress gateway you mention covers most of it, as long as DNS also goes through that gateway, or it turns into the side channel.

On the drift con, one approach that helps: treat the sandbox filesystem as the source of truth for files and the session DB as the source of truth for the conversation only, and after each tool result write a small record into the session (tool call id plus a hash of the paths it touched). After a crash you can tell whether the tool already ran without running it again.

Disclosure: I work on Sandscale, which runs agent code in Firecracker microVMs, so I mostly see the hands side. Curious how the coupled side handles a turn that is mid-command when the actor gets snapshotted.

Collapse
 
sara_builds profile image
Sara •

The Cloud Run timeout story really clicked for me. I've seen a "just wrap the local loop in a web service" setup fall apart the first time a turn outlives the request, and then you're suddenly building a task store and reconnect path you didn't plan for. The "does orchestration need a life of its own" test is a useful filter — for a workspace-heavy coding agent that sits idle between turns, keeping brain and hands in one box looks less like a compromise than I used to think. Curious how you keep brain-side tools from becoming a confused-deputy path when one process serves every user.

Collapse
 
aiframe profile image
AI Frame •

The two kinds of idle time framing is what stuck with me. I have mostly built small agents where everything lives in one place, so the coupled setup felt natural, but the point about paying for a sandbox while the model thinks is a real cost once turns get long. The decision questions at the end are a useful shortcut too — if most turns never touch the shell, keeping the brain outside makes a lot of sense.

Collapse
 
vexaloom-labs profile image
vexaloom-labs •

Persisted conversation history gives poisoned instructions a return ticket even after the sandbox is replaced.

Collapse
 
ric0c0derlab profile image
Ric0 C0der Lab •

Separating inference from execution is particularly appealing in a homelab. You can upgrade the model without giving it direct access to every system.

Collapse
 
the_daily_flare profile image
The daily flare •

Your 1,000 concurrent requests per instance figure made me rethink how cheap waiting on the model can be.