What you will be able to do
- Choose between the Client SDK, the Agent SDK and Claude Managed Agents based on how much of the agent loop, the tools and the hosting each one handles for you
- Describe the four building blocks of Claude Managed Agents: agent, environment, session and events
- Tell apart three deployment models: the Agent SDK in your own process, Managed Agents in Anthropic's cloud sandbox, and Managed Agents with a self-hosted sandbox
Key concept
Agent harness — The harness is the code that runs the agent loop around the model. It sends the prompt, executes the tools Claude asks for, feeds the results back and decides when to stop. The ways to build a Claude agent mostly differ in who writes and runs that harness: you, a library in your process, or Anthropic.
1.Four ways to build a Claude agent
Every Claude agent runs the same cycle. Claude gets a prompt, asks for tool calls, gets the results back, and keeps going until it answers with no tool call. That cycle is taught in [The tool-use (agentic) loop](lesson:8.1). The build options differ in how much of that cycle you write yourself, which tools are already there, and where the agent runs.
At one end is the Client SDK, which calls the Claude API directly. You write the tool loop yourself, or you hand it to the client SDK's beta tool runner, which drives the loop while you still define and run every tool. That control is the point: the Messages API is described as best for custom agent loops and fine-grained control, so a custom harness belongs here.
The Agent SDK is the middle option. It is a Python or TypeScript library that runs the Claude Code binary inside a process you operate. Claude Code is Anthropic's agent for working from a terminal, with built-in tools to read, edit and write files and to run commands; the SDK reuses its loop and tools as a library. You get Claude Code's loop already built, along with its built-in tools, permissions, sessions, hooks, subagents and MCP support, and you never write the loop yourself. The Claude Managed Agents service sits at the far end: Anthropic hosts the harness, and you configure it through the Claude API.
| You want to | Use | Who runs the loop | Tools |
|---|---|---|---|
| Call the Claude API directly from your own code | Client SDK | You, or the beta tool runner | Ones you define and execute |
| Embed Claude Code's agent in your own Python or TypeScript application | Agent SDK | The SDK, in a process you operate | Built-in Read, Edit, Bash, Grep and more, plus MCP |
| Have Anthropic host the agent, configured through the Claude API | Managed Agents | Anthropic's hosted harness | Built-in Bash, file operations, web search and fetch, MCP |
| Do interactive development or one-off tasks from a terminal | Claude Code CLI | Claude Code | Built-in |
Each option wins in a different situation. Pick the Client SDK when the loop itself is the product, for example when you need a custom stopping rule or your own way of trimming context. Pick the Agent SDK when you want a working coding-style agent inside your own service this week. Pick Managed Agents when the work runs for minutes or hours and you would rather not run the sandbox, the tool-execution layer or session storage yourself.
Checkpoint 1 of 3· Check yourself
A team wants Claude Code's built-in file and shell tools, hooks and sessions inside their own Python service, and does not want to write the tool loop. Which option fits?
The Agent SDK is a library that runs Claude Code's loop and built-in tools in a process you operate. The Client SDK, with or without the tool runner, still leaves you to define the tools.
“Embed Claude Code’s agent in your own Python or TypeScript application, in a process you operate”Source: code.claude.com
2.Claude Managed Agents: agent, environment, session, events
With Managed Agents, configuration replaces most of your code. You do not build an agent loop, a tool-execution layer or a runtime. You describe the agent, and Anthropic's harness runs it, with prompt caching and compaction built in. Four concepts cover the whole service.
These are the four concepts:
- Agent: the model, system prompt, tools, MCP servers and skills. You create it once and reference it by ID across sessions. - Environment: where sessions run, either an Anthropic-managed cloud sandbox or a self-hosted sandbox on your own infrastructure. - Session: one running agent instance inside an environment, doing a specific task. - Events: the messages between your application and the agent, such as user turns, tool results and status updates.
At runtime you start a session that points at an agent and an environment. You send user messages as events, and Claude runs tools on its own while it streams results back over server-sent events. Event history is stored on the server, so you can fetch it in full later. While the agent works you can send more user events to steer it, or interrupt it to change direction.
The service fits long-running execution, stateful sessions with persistent filesystems, and recurring runs on a cron schedule through scheduled deployments. That statefulness has a cost. Sessions store conversation history, sandbox state and outputs on Anthropic's side, so Managed Agents is not currently eligible for Zero Data Retention or HIPAA BAA coverage. You can still delete sessions and uploaded files through the API.
Checkpoint 2 of 3· Match them up
Match each Managed Agents concept to what it holds
Tap a term, then the definition that fits it.
You define the agent once, choose an environment, and start sessions that reference both. Events are the traffic going in and out of a running session.
“Create the agent once and reference it by ID across sessions.”Source: platform.claude.com
Sources2
3.Your process, Anthropic's cloud, or your sandbox
There are three places an agent can run, and the question that separates them is which side runs the loop and which side runs the tools. With the Agent SDK, both happen in your process. You deploy it like any other service, in a container or on serverless infrastructure, and you store sessions in your own backend if you need them to persist.
Managed Agents runs tools in Anthropic-managed cloud sandboxes by default. Anthropic handles network egress controls, file and repo mounting, and the sandbox lifecycle. A self-hosted sandbox keeps the orchestration on Anthropic's side but runs the tools on your infrastructure. The files the agent reads and writes, the processes it starts and the network it can reach all stay under your control. Tool inputs and outputs still go back to Anthropic's control plane, because that is where Claude runs. Skills and memory store contents are copied into your sandbox for the session. Memory stores are the agent's memory files, which Anthropic keeps; on your side, the SDK worker downloads them to /mnt/memory/ and syncs the agent's changes back to the store.
| Concern | Cloud environment | Self-hosted sandbox |
|---|---|---|
| Where tools run | Anthropic-managed sandboxes | Your infrastructure |
| Network reach | Anthropic's egress controls | Your network policy |
| File and GitHub repo mounting | Managed by Anthropic | Managed by you |
| Memory stores | Mounted by Anthropic at /mnt/memory/ | Downloaded to /mnt/memory/ and synced by the SDK worker |
| Lifecycle | Managed by Anthropic | Managed by you |
Self-hosting earns its operational cost in three cases: the data cannot leave your network boundary, the agent has to reach internal services that are not publicly routable, or the work has to run under your own compliance and audit controls. Locking down what a sandboxed process can reach is covered in [Runtime sandboxing against exfiltration](lesson:7.1). If none of those cases apply, the cloud environment means less infrastructure for you to run.
Checkpoint 3 of 3· Check yourself
An agent must query an internal inventory service with no public route, and the team wants Anthropic to run the agent loop. Which deployment fits?
A self-hosted sandbox runs tools inside your network, so they can reach internal services, while Anthropic keeps running the orchestration.
“reach internal services that are not publicly routable”Source: platform.claude.com
Exam traps
Each one states something that sounds right. Open it to see what is actually true.
1.A self-hosted sandbox means the whole agent, model calls included, runs inside your infrastructure.Why is that wrong?
Only tool execution moves to your host. Orchestration stays with Anthropic, and tool inputs and outputs still go to Anthropic's control plane.
2.Managed Agents can be used for a workload that requires Zero Data Retention.Why is that wrong?
Managed Agents stores session history, sandbox state and outputs on the server by design, so it is not currently eligible for ZDR or HIPAA BAA coverage.
Covered in Claude Managed Agents: agent, environment, session, events
Sources
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://code.claude.com/docs/en/agent-sdk/overviewOfficial docs
“You write the tool loop yourself”
↩︎ Four ways to build a Claude agent“Do interactive development or run one-off tasks from a terminal”
↩︎ Four ways to build a Claude agent“A hosted agent harness that runs the agent loop”
↩︎ Four ways to build a Claude agent“Embed Claude Code’s agent in your own Python or TypeScript application, in a process you operate”
↩︎ Checkpoint - 2.
“Custom agent loops and fine-grained control”
↩︎ Four ways to build a Claude agent“Instead of building your own agent loop, tool execution, and runtime, you get a fully managed environment”
↩︎ Claude Managed Agents: agent, environment, session, events“Long-running execution: Tasks that run for minutes or hours with multiple tool calls”
↩︎ Claude Managed Agents: agent, environment, session, events“Self-hosted execution: Sandboxes on infrastructure you control for compliance or data-residency requirements”
↩︎ Your process, Anthropic's cloud, or your sandbox“Claude Managed Agents provides the harness and infrastructure for running Claude as an autonomous agent.”
↩︎ Key concept“Managed Agents is not currently eligible for Zero Data Retention or HIPAA Business Associate Agreement (BAA) coverage”
↩︎ Exam trap 2“Create the agent once and reference it by ID across sessions.”
↩︎ Checkpoint - 3.https://code.claude.com/docs/en/agent-sdk/agent-loopOfficial docs
“See Hosting the Agent SDK for container and serverless guidance”
↩︎ Your process, Anthropic's cloud, or your sandbox - 4.
“changes the agent makes to memory files sync back to the store”
↩︎ Your process, Anthropic's cloud, or your sandbox“Tool inputs and outputs still flow to Anthropic's control plane (where Claude runs)”
↩︎ Exam trap 1“Self-hosted sandboxes keep the orchestration on Anthropic's side but move tool execution into infrastructure you control”
↩︎ Prediction“reach internal services that are not publicly routable”
↩︎ Checkpoint