I reread the first version of this article late one night at the end of October, and my hands stopped at the code samples. I had written calls like client.managed_agents.sessions.create(...) that I can't find anywhere in the official docs. I'd filled in the beta's blanks from guesswork before checking, and rereading it was uncomfortable.
So I went back through the documentation one page at a time and rewrote this with only what I could confirm. If I can't confirm it, I say so. For API articles, that's a line I'd rather not cross again.
Here's the short version: Managed Agents hands the agent loop and the sandbox to Anthropic. That's a different place to put responsibility than building the loop yourself on the Messages API.
What it is
Claude Managed Agents is a managed harness for running Claude as an autonomous agent. Claude reads files, runs commands, browses the web and runs code, and the environment it does that in is provided for you. Prompt caching and compaction live in the harness too.
It fits long tasks (minutes to hours) and asynchronous work. If you want fine-grained control inside the loop, building your own on the Messages API is still the more natural choice.
The official status is beta. Every endpoint needs the managed-agents-2026-04-01 beta header; the official SDK sets it for you. The docs also say behavior may be refined between releases.
Four concepts
| Concept | What it is |
|---|---|
| Agent | The model, system prompt, tools, MCP servers and skills |
| Environment | Where sessions run: an Anthropic-managed cloud sandbox, or a self-hosted one |
| Session | A running agent instance in an environment, doing one task |
| Events | Messages between your app and the agent (user turns, tool results, status updates) |
The easy mistake is treating an agent and a session as the same thing. An agent is the blueprint you create once and reuse by ID; a session is one run of that blueprint. Keeping them apart clears up a lot.
The minimal flow
- Create an agent (model, prompt, tools).
- Create an environment.
- Start a session that references both.
- Send events and stream the response over SSE.
- Steer or interrupt if needed.
The official quickstart creates the agent and environment with the ant CLI. The agent is a Markdown file:
---
name: Coding Assistant
model: claude-opus-5-5
tools:
- type: agent_toolset_20260401
---
You are a helpful coding assistant. Write clean, well-documented code.agent_toolset_20260401 turns on the built-in toolset (bash, file operations, web search). The environment is YAML:
name: quickstart-env
config:
type: cloud
networking:
type: limited
allow_package_managers: trueant apply coding-assistant.md environment.yamlThis prints the agent ID and records it in claude-lock.json. I'm not covering SDK calls for creating agents or environments, because I couldn't find an example in the quickstart.
Start a session and read events
import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY
session = client.beta.sessions.create(
agent=agent_id, # ID printed by ant apply
environment_id=environment_id,
title="Quickstart session",
)
with client.beta.sessions.events.stream(session.id) as stream:
# Open the stream first, then send the message
client.beta.sessions.events.send(
session.id,
events=[
{
"type": "user.message",
"content": [
{"type": "text", "text": "Write a Python script that saves the first 20 Fibonacci numbers to fibonacci.txt"},
],
},
],
)
for event in stream:
match event.type:
case "agent.message":
for block in event.content:
if block.type == "text":
print(block.text, end="")
case "agent.tool_use":
print(f"\n[tool: {event.name}]")
case "session.status_idle":
print("\nAgent finished.")
breakNote the order: the stream is opened before the message is sent, so the first events aren't missed. The four event types here are user.message, agent.message, agent.tool_use and session.status_idle; the full list is in the official reference.
How billing works
Billing has two dimensions, tokens and session runtime.
- Session runtime: $0.08 per session-hour, metered to the millisecond while the session is
running. - Idle time is free: time spent
idle(waiting for your next message or a tool confirmation),reschedulingorterminatedisn't billed as runtime. - Tokens: billed at the normal model rates, with the usual prompt-caching multipliers.
- Web search: $10 per 1,000 searches inside a session.
The official worked example is a one-hour session on Claude Opus 5.5 with 50,000 input and 15,000 output tokens: $0.58 in total. If 40,000 of those input tokens are cache reads, it drops to $0.428. The $0.08 runtime fee is the smaller part; tokens dominate. The Batch API discount doesn't apply to sessions. Prices can change, so check the official pricing page before budgeting.
Check these before you adopt it
Managed Agents is not eligible for Zero Data Retention or HIPAA BAA coverage. Sessions are stateful: conversation history, sandbox state and outputs are stored server-side. You can delete sessions and uploaded files through the API, but for sensitive work you'll want to decide up front what you hand over.
MCP tunnels and "dreaming" are in a narrower research preview and need an access request.
Where I'd still use something else
When I need my own logic inside the loop, or deep integration with an existing database, I still build the loop myself with the Messages API or the Agent SDK. For long jobs like "write the code, run it, hand back the files," handing the whole thing over saves visible operational effort. I'd rather keep both and choose by the shape of the work.
For production design, see running Managed Agents in production.
One next step
Create a small agent and environment with ant apply, run a single session with the code above, and compare how long it takes to reach idle with the billing breakdown. That will give you a feel for the cost faster than any table. I plan to keep the rule from the top of this page: confirmed things only.