camzabriskie.com

Primers › Working with AI

Where an agent runs, and what it costs in setup and waiting

05 / 06 updated Oct 17, 2026
On this page
  1. A few terms
  2. Five common setups
  3. Where the time in a run goes
  4. Setup, from least to most
  5. What the agent can reach
    1. A private MCP server behind a VPN
  6. Making a slow agent faster
  7. Which to pick
  8. References

Agent harnesses explains the loop: the model asks for a tool, the harness runs it, the result goes back, and that repeats until the job is done. This primer assumes you’ve read it, and links back to it wherever it leans on an idea from there. The model always runs on the provider’s servers. The harness and its tools can run on your laptop, on servers you run, or on the provider’s side, and the choice decides how long setup takes, how long the agent waits on each turn, what it can reach, and whether it keeps going after you close the lid.

A few terms

Five common setups

The running example is the bookshelf fix from Agent harnesses. In short: isExpired in src/auth.ts compares a token’s expiry, counted in seconds, with Date.now(), counted in milliseconds, so every token looks expired and one test fails. You ask the agent to fix the failing test, and it gets there in four turns:

  1. Run npm test, which names the failing test and the wrong answer.
  2. Read src/auth.ts and its test, which shows the seconds and milliseconds mismatch.
  3. Change the comparison to token.exp * 1000 < Date.now(), then run npm test again. Everything passes.
  4. Report what was wrong. No tool calls, so the loop ends.

Every setup below runs those same four turns, and the model makes the same decisions in each. The setups differ only in which machine runs npm test, and in which part of each turn has to cross the internet. Five setups cover most of what you’ll meet:

  1. Local CLI. Claude Code (or a similar tool) in a terminal on your laptop. The loop and the tools run on your machine [4], so npm test runs against your own checkout.
  2. Agent SDK on your own servers. Your application starts the harness as a subprocess, in a container you run. Loop and tools are both in your container [2].
  3. Cloud session. Claude Code started from the browser, the phone app, or claude --cloud, running in an isolated VM that Anthropic manages [5].
  4. Managed agent, cloud environment. Anthropic runs the loop and gives each session a fresh Linux container for the tools [3]. npm test runs in that container, against a copy of bookshelf you gave the session.
  5. Managed agent, self-hosted sandbox. Anthropic still runs the loop, but a worker process on your infrastructure claims the session, runs each tool call locally, and posts the result back [6]. npm test runs on your worker.

The dashed line is the internet between you and the provider. In rows 1, 2 and 5 every turn crosses it once: for the model call in 1 and 2, for the tool call in 5. Rows 3 and 4 keep the whole turn on the provider's side.

Where the time in a run goes

Each turn costs the model’s time to respond, the tool’s time to run, and one round trip for whichever of those is on the far side of the dashed line. The loop diagram in Agent harnesses shows why: the model is at the other end of an API, so every tool call means at least one extra round trip, and for small tasks that overhead can exceed the work itself [1].

Here is the bookshelf run with made-up timings you should replace with your own. Say the model takes 5 seconds to respond each turn, npm test takes 4 seconds, reading or editing a file takes 0.1 seconds, and a round trip between you and the provider takes 0.1 seconds:

TurnModelToolsRound trip
1 Run the tests5 s4 s0.1 s
2 Read two files5 s0.1 s0.1 s
3 Edit, run the tests again5 s4.1 s0.1 s
4 Report5 snone0.1 s
Total, 28.6 s20 s8.2 s0.4 s

The round trips are at most 0.4 seconds, in a local CLI or your own containers, where all four model calls cross the line. With a self-hosted worker it’s 0.3, because turn 4 calls no tool. Moving the loop next to the model (row 4) or next to the tools (rows 1 and 2) can only win back part of that 0.4. Three other things move the total much more:

To see your own round trip to the API, time one request. The output shows when the TCP connection, the TLS handshake, and the first byte of the reply each finished, counted from the start [8]:

macOS / Linux

curl -o /dev/null -s -w 'connect %{time_connect}s  tls %{time_appconnect}s  first byte %{time_starttransfer}s\n' https://api.anthropic.com/

Windows (PowerShell)

(Measure-Command { try { Invoke-WebRequest https://api.anthropic.com/ -UseBasicParsing } catch {} }).TotalMilliseconds

The macOS and Linux version prints one line like this:

connect 0.031s  tls 0.072s  first byte 0.118s

connect is roughly one network round trip, tls adds the handshake, and first byte is the whole request, including a little time for the server to answer. The PowerShell version prints one number, the total time in milliseconds, comparable to first byte [9] [10]. The catch is there because the bare URL returns an error status, and only the timing matters here. If the number is a few hundredths of a second, the line in the diagram costs you almost nothing per turn.

Setup, from least to most

The setups differ much more in what you have to build and run than in per-turn latency.

Local CLI. Install it and sign in. The tools are your own machine’s tools, so npm test uses the Node and the node_modules you already have, and there’s no cold start beyond launching the program. It also stops when your laptop sleeps. Claude Code’s Remote Control lets you steer a local session from your phone or a browser, but the session still runs on your machine, so the machine has to stay on [11].

Cloud session. No hosting, but the first session in an environment pays a cold start: the VM clones the repository and runs your setup script, a Bash script that installs whatever isn’t pre-installed [12]. If the script finishes in roughly five minutes, Anthropic snapshots the filesystem and later sessions start from the snapshot and skip it. The snapshot is rebuilt when you change the script or the allowed hosts, or after about seven days. It keeps files, not running processes, so a database the script started has to be started again in each session [12]. An idle session’s VM pauses after a few minutes with its files saved and resumes on your next message [12].

Managed agent, cloud environment. Nothing to operate. Each session gets a fresh container with common languages and tools already installed, and you set its network rules and any extra packages [3]. You talk to it through an API, which suits an agent built into your own product.

Agent SDK on your own servers. You build and run the container. Anthropic’s hosting guide suggests 1 GiB of RAM, 5 GiB of disk, and 1 CPU per agent as a starting point, and points out that session transcripts live on the container’s local disk and vanish on a restart unless you copy them to a store [2]. It describes a few patterns, each with its own cold-start trade-off [2]:

PatternContainer lifetimeCold start
EphemeralOne container per task, destroyed afterPaid every task, so it needs to be sub-second
Long-runningStays up and serves many sessionsPaid once, and the SDK can pre-warm processes before traffic arrives
HybridSpins down when idle, restores the session from a store when the user comes backPaid after each idle period

Managed agent, self-hosted sandbox. You run the worker hosts, harden them, control their egress, and rotate the key the worker uses. You also give up some of the cloud environment’s conveniences, such as automatic mounting of files and GitHub repositories and the pre-installed runtimes [3].

What the agent can reach

Where the tools run decides which network they’re on, and that is often what makes the choice for you.

MCP servers follow their own rule. When Anthropic’s side connects to an MCP server, through the API’s MCP connector or a managed agent, the server has to be reachable over HTTP from the internet [13]. That’s true even with a self-hosted sandbox, because Anthropic, not your worker, connects to the agent’s MCP servers [3]. For a server that must stay private, MCP tunnels carry the traffic over an outbound-only connection from your network, so no inbound port has to be opened. They were a research preview when this was written [14].

A self-hosted sandbox keeps files, not results

With a self-hosted sandbox the files and processes stay on your worker, but the conversation and every tool result still go to Anthropic, because that’s how the model sees what a tool returned [3]. If npm test prints a secret, the model sees the secret. Keeping data in your network means keeping it out of what the tools return, too.

A private MCP server behind a VPN

Say you’ve written an MCP server that speaks HTTP and runs at a private address, http://10.0.8.25:8000/mcp, on a network you reach through a VPN. With the VPN on, Claude Code on your laptop can use it. The API’s MCP connector can’t, and neither can a managed agent. Each one opens the connection from a different machine.

The model never connects to an MCP server. As in the bookshelf run, it answers with a tool call, and the harness does the work: here the harness’s MCP client sends the request. Register the server with Claude Code on your laptop [15]:

claude mcp add --transport http notes http://10.0.8.25:8000/mcp

Each call then goes like this:

  1. The model, on the provider’s side, answers with a tool call: a tool name and its arguments.
  2. Claude Code on your laptop receives it and sends the MCP request to 10.0.8.25.
  3. Your laptop has a route to that address through the VPN, so the request arrives.
  4. Claude Code sends the server’s answer back to the model as a tool result.

The provider sees the tool name, the arguments, and the result, but never connects to the address. Turn the VPN off and step 3 fails, the same way curl would.

The server and the model are the same in both pictures. Only the MCP client moved, and the client is the one that needs a route to 10.0.8.25.

Now point the same server at a harness whose MCP client runs on Anthropic’s side:

Three ways to reach a private server from the provider’s side:

OptionHow it reaches the serverCost
MCP tunnelA connector inside your network opens an outbound-only connection, and Anthropic sends MCP traffic back through it [14]Research preview, needs an access request, and you run the tunnel stack
Custom tool on a self-hosted workerThe worker runs inside your network and can serve custom tools of its own [3], so it can make the call the MCP server would have madeManaged agents only, and you run the worker
Public endpoint with OAuthThe connector accepts OAuth bearer tokens for authenticated servers [13]Gives up the privacy the VPN was there for

If only you use the server, from your own laptop, none of these is needed. A local client with the VPN on is already the simplest setup that works.

Making a slow agent faster

The levers, in the order the arithmetic above suggests:

  1. Cut turns. Let independent reads run in one turn [7], and don’t hand the model a tool for something it can answer without one [1].
  2. Cache the prompt. Each request re-sends the whole conversation, as Agent harnesses shows for bookshelf’s turn 4. Prompt caching lets the API reuse a prefix it has already processed (the system prompt, the tool definitions, the conversation so far), which cuts the time to the first token of each response [16]. Prompt caching works through the bookshelf numbers, and the mistakes that quietly turn it off.
  3. Pay the cold start once. Keep setup-script work under the cache limit in a cloud session [12], or keep SDK containers warm when users arrive in bursts [2].
  4. Speed up the slowest tool. In bookshelf, npm test ran twice and was nearly all of the tool time. A test command that runs only the affected tests helps every turn that runs it.

Which to pick

Your situationStart with
Working interactively on code that’s on your laptopLocal CLI
A long task you want to leave running, or several at onceCloud session (claude --cloud "…" starts one from a terminal [5])
Steering a local session from your phoneLocal CLI with Remote Control
An agent inside your own product, without running sandboxesManaged agent, cloud environment
An agent inside your product, with full control of the containerAgent SDK on your servers
Tools that must run inside your networkSelf-hosted sandbox, or a local CLI on a machine inside it

Anthropic’s own advice for managed agents is to start with the cloud environment and move to a self-hosted sandbox only when tools must run on infrastructure you control [3]. The same reasoning works for the rest of the table: begin where setup is cheapest, and move only when the reach or the data rules force it, since per-turn latency rarely decides it.

References

Show all 16 sourcesHide sources
  1. [1] ↩ a b c Anthropic, “How tool use works,” Claude Platform Documentation. Accessed: Oct. 17, 2026. [Online]. Available: https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool-use-works
  2. [2] ↩ a b c d e Anthropic, “Hosting the Agent SDK,” Claude Code Documentation. Accessed: Oct. 17, 2026. [Online]. Available: https://code.claude.com/docs/en/agent-sdk/hosting
  3. [3] ↩ a b c d e f g h i j Anthropic, “Choosing an agent environment,” Claude Platform Documentation. Accessed: Oct. 17, 2026. [Online]. Available: https://platform.claude.com/docs/en/managed-agents/choosing-an-environment
  4. [4] ↩ a b Anthropic, “Configure the sandboxed Bash tool,” Claude Code Documentation. Accessed: Oct. 17, 2026. [Online]. Available: https://code.claude.com/docs/en/sandboxing
  5. [5] ↩ a b Anthropic, “Use Claude Code in the cloud,” Claude Code Documentation. Accessed: Oct. 17, 2026. [Online]. Available: https://code.claude.com/docs/en/claude-code-on-the-web
  6. [6] ↩ Anthropic, “Self-hosted sandboxes,” Claude Platform Documentation. Accessed: Oct. 17, 2026. [Online]. Available: https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes
  7. [7] ↩ a b Anthropic, “Parallel tool use,” Claude Platform Documentation. Accessed: Oct. 17, 2026. [Online]. Available: https://platform.claude.com/docs/en/agents-and-tools/tool-use/parallel-tool-use
  8. [8] ↩ curl project, “curl man page,” curl documentation. Accessed: Oct. 17, 2026. [Online]. Available: https://curl.se/docs/manpage.html
  9. [9] ↩ Microsoft, “Measure-Command,” PowerShell 7.5 Documentation. Accessed: Oct. 17, 2026. [Online]. Available: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/measure-command
  10. [10] ↩ Microsoft, “Invoke-WebRequest,” PowerShell 7.5 Documentation. Accessed: Oct. 17, 2026. [Online]. Available: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest
  11. [11] ↩ Anthropic, “Continue local sessions from any device with Remote Control,” Claude Code Documentation. Accessed: Oct. 17, 2026. [Online]. Available: https://code.claude.com/docs/en/remote-control
  12. [12] ↩ a b c d e f g Anthropic, “Configure cloud environments,” Claude Code Documentation. Accessed: Oct. 17, 2026. [Online]. Available: https://code.claude.com/docs/en/cloud-environments
  13. [13] ↩ a b c Anthropic, “MCP connector,” Claude Platform Documentation. Accessed: Oct. 17, 2026. [Online]. Available: https://platform.claude.com/docs/en/agents-and-tools/mcp-connector
  14. [14] ↩ a b Anthropic, “MCP tunnels,” Claude Platform Documentation. Accessed: Oct. 17, 2026. [Online]. Available: https://platform.claude.com/docs/en/agents-and-tools/mcp-tunnels
  15. [15] ↩ Anthropic, “Connect Claude Code to tools via MCP,” Claude Code Documentation. Accessed: Oct. 17, 2026. [Online]. Available: https://code.claude.com/docs/en/mcp
  16. [16] ↩ Anthropic, “Prompt caching,” Claude Platform Documentation. Accessed: Oct. 17, 2026. [Online]. Available: https://platform.claude.com/docs/en/build-with-claude/prompt-caching

Every source cited across the primers is collected on one page.