◉CLAUDE LABJP
●SONNET 4.5 — Sonnet 4.5 was retired from the Claude API on 11/30. Calls now return an error. Move to Sonnet 5.5●PROJECTS — The Enterprise Analytics API now reports daily usage for the new projects experience (beta)●OPUS 4.5 — claude-opus-4-5 retires on 2027/1/22, 52 days from now. The replacement is claude-opus-5-5●LANGUAGE — Some users say Claude switches to another language mid-session while they write in English●NEW — New: Weekly usage looks like it jumped right after a plan upgrade? Check this first●COWORK — Handing Cowork a folder for the first time? Start with a task that only reads files●SONNET 4.5 — Sonnet 4.5 was retired from the Claude API on 11/30. Calls now return an error. Move to Sonnet 5.5●PROJECTS — The Enterprise Analytics API now reports daily usage for the new projects experience (beta)●OPUS 4.5 — claude-opus-4-5 retires on 2027/1/22, 52 days from now. The replacement is claude-opus-5-5●LANGUAGE — Some users say Claude switches to another language mid-session while they write in English●NEW — New: Weekly usage looks like it jumped right after a plan upgrade? Check this first●COWORK — Handing Cowork a folder for the first time? Start with a task that only reads files
Articles/API & SDK
⬡ API & SDK/2026-04-09Intermediate

Getting Started with Claude Managed Agents: Agent, Environment, Session

A first-steps guide to Claude Managed Agents: the four concepts (agent, environment, session, events), the managed-agents-2026-04-01 beta header, a minimal session in Python, billing (tokens plus $0.08 per session-hour), and the ZDR/HIPAA caveat, all checked against the official docs.

managed-agents6claude-api85agent14enterprise5api39202615

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

ConceptWhat it is
AgentThe model, system prompt, tools, MCP servers and skills
EnvironmentWhere sessions run: an Anthropic-managed cloud sandbox, or a self-hosted one
SessionA running agent instance in an environment, doing one task
EventsMessages 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

  1. Create an agent (model, prompt, tools).
  2. Create an environment.
  3. Start a session that references both.
  4. Send events and stream the response over SSE.
  5. 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: true
ant apply coding-assistant.md environment.yaml

This 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.")
                break

Note 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), rescheduling or terminated isn'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.

Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

If you found this article helpful, a small tip ($1.50) would mean a lot to us. Your support helps keep this site ad-free and covers server and hosting costs.

Related Articles

⬡ API & SDK2026-11-23
How Many Input Tokens Does One More Tool Add? Separate the Fixed Overhead From Each Tool's Weight With count_tokens
Passing tools adds a fixed, model-specific block of tokens on top of the definitions themselves. A leave-one-out script for count_tokens, what to check when the fixed part doesn't match the docs, and how to read the shift from Opus 4.5 or Sonnet 4.6 to the 5.5 models in both tokens and dollars: the fixed part shrinks while the definitions grow.
⬡ API & SDK2026-11-20
When the Claude API Only Says “Connection error.”, Follow the Exception Three Levels Down and Sort It Into Four Causes
The Python SDK raises the same APIConnectionError message for DNS, proxy, certificate, and timeout failures. Here is a script that walks __cause__, the real output from reproducing all four, and the order I fix them in.
⬡ API & SDK2026-09-22
Character counts won't predict PDF input tokens — bracket the cost per page before you send
How to estimate the input tokens of a PDF before sending it to the Claude API, by bracketing from page count rather than character count. Includes a measured 6.6x gap on a nine-page A4 document, the two separate increases that come with current models, and the count_tokens limitation that bites when you use file_id.