Where an agent runs, and what it costs in setup and waiting
On this page
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
- Harness, tool, turn: as defined in Agent harnesses. The harness runs the loop, a tool is an operation the model can ask for, and a turn is one trip around the loop.
- Latency: time spent waiting. Here, mostly the time a turn takes from the model’s request to the next model call.
- Round trip: a request going out and its answer coming back. Every turn includes at least one, because the model is on the other end of an API [1].
- Cold start: the time from asking for a fresh environment to it being ready for the first request [2]. A container that has to install Node and your dependencies before the agent can run
npm testhas a long one. - Sandbox: an isolated place, such as a container, where the agent’s tools run and work on files [3].
- Egress: traffic going out of a network. A sandbox’s egress rules decide which outside hosts the agent can reach.
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:
- Run
npm test, which names the failing test and the wrong answer. - Read
src/auth.tsand its test, which shows the seconds and milliseconds mismatch. - Change the comparison to
token.exp * 1000 < Date.now(), then runnpm testagain. Everything passes. - 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:
- 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 testruns against your own checkout. - 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].
- Cloud session. Claude Code started from the browser, the phone app, or
claude --cloud, running in an isolated VM that Anthropic manages [5]. - Managed agent, cloud environment. Anthropic runs the loop and gives each session a fresh Linux container for the tools [3].
npm testruns in that container, against a copy ofbookshelfyou gave the session. - 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 testruns 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:
| Turn | Model | Tools | Round trip |
|---|---|---|---|
| 1 Run the tests | 5 s | 4 s | 0.1 s |
| 2 Read two files | 5 s | 0.1 s | 0.1 s |
| 3 Edit, run the tests again | 5 s | 4.1 s | 0.1 s |
| 4 Report | 5 s | none | 0.1 s |
| Total, 28.6 s | 20 s | 8.2 s | 0.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:
- The number of turns. Each turn you avoid saves a whole model response. In turn 2 the model read both files in one turn. Had it read them one turn at a time, the run would take one more turn, 5 + 0.1 = 5.1 seconds longer. Claude can ask for several tools in one turn, and independent read-only calls like those two reads are the usual candidates [7].
- How slow the tools are. If
npm testtook 40 seconds instead of 4, the tools column would be 40 + 0.1 + 40.1 = 80.2 seconds, and a faster machine for the tests would matter far more than where the loop is. - The cold start. If a fresh container spends 3 minutes installing
bookshelf’s dependencies before turn 1, that 180 seconds is more than six times the whole run.
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]:
| Pattern | Container lifetime | Cold start |
|---|---|---|
| Ephemeral | One container per task, destroyed after | Paid every task, so it needs to be sub-second |
| Long-running | Stays up and serves many sessions | Paid once, and the SDK can pre-warm processes before traffic arrives |
| Hybrid | Spins down when idle, restores the session from a store when the user comes back | Paid 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.
- Local CLI: whatever your laptop can reach, including a VPN you’re connected to. Claude Code’s optional sandbox can restrict shell commands to the domains you allow, on macOS, Linux and WSL2 [4].
- Cloud session: whatever the environment’s network access level allows. The levels are None, Trusted (package registries, GitHub, cloud SDKs and other allowlisted domains), Full, and Custom [12]. Nothing on your private network.
- Self-hosted sandbox or your own containers: your network. The worker runs bash and file tools inside it, so they can reach internal hosts that aren’t publicly routable [3].
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:
- The model, on the provider’s side, answers with a tool call: a tool name and its arguments.
- Claude Code on your laptop receives it and sends the MCP request to
10.0.8.25. - Your laptop has a route to that address through the VPN, so the request arrives.
- 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:
- The API’s MCP connector connects from Anthropic’s servers and only reaches servers exposed over HTTP from the internet [13]. A private address isn’t.
- A managed agent has the same problem, even with a self-hosted sandbox inside your network, because Anthropic connects to the agent’s MCP servers and the worker doesn’t [3].
- MCP connectors enabled on a cloud session also travel through Anthropic’s servers, not the session’s network [12].
- A cloud session reads the repository’s
.mcp.jsonand runs those servers from its own VM [12], whose network reaches only what the environment’s access level allows. Your VPN isn’t one of those.
Three ways to reach a private server from the provider’s side:
| Option | How it reaches the server | Cost |
|---|---|---|
| MCP tunnel | A 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 worker | The 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 made | Managed agents only, and you run the worker |
| Public endpoint with OAuth | The 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:
- 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].
- 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 thebookshelfnumbers, and the mistakes that quietly turn it off. - 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].
- Speed up the slowest tool. In
bookshelf,npm testran 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 situation | Start with |
|---|---|
| Working interactively on code that’s on your laptop | Local CLI |
| A long task you want to leave running, or several at once | Cloud session (claude --cloud "…" starts one from a terminal [5]) |
| Steering a local session from your phone | Local CLI with Remote Control |
| An agent inside your own product, without running sandboxes | Managed agent, cloud environment |
| An agent inside your product, with full control of the container | Agent SDK on your servers |
| Tools that must run inside your network | Self-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] ↩ 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] ↩ 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] ↩ 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] ↩ 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] ↩ 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] ↩ 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] ↩ 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] ↩ curl project, “curl man page,” curl documentation. Accessed: Oct. 17, 2026. [Online]. Available: https://curl.se/docs/manpage.html
- [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] ↩ 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] ↩ 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] ↩ 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] ↩ 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] ↩ 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] ↩ 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] ↩ 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.