Loading...
    • Build
    • Admin
    • Models & pricing
    • Client SDKs
    • API Reference
    Search...
    ⌘K
    First steps
    Intro to ClaudeQuickstart
    Building with Claude
    Features overviewUsing the Messages APIHandling stop reasons
    Model capabilities
    Extended thinkingAdaptive thinkingEffortFast mode (beta: research preview)Structured outputsCitationsStreaming MessagesBatch processingSearch resultsStreaming refusalsMultilingual supportEmbeddings
    Tools
    OverviewHow tool use worksWeb search toolWeb fetch toolCode execution toolMemory toolBash toolComputer use toolText editor tool
    Tool infrastructure
    Tool searchProgrammatic tool callingFine-grained tool streaming
    Context management
    Context windowsCompactionContext editingPrompt cachingToken counting
    Working with files
    Files APIPDF supportImages and vision
    Skills
    OverviewQuickstartBest practicesSkills for enterpriseSkills in the API
    MCP
    Remote MCP serversMCP connector
    Prompt engineering
    OverviewPrompting best practicesConsole prompting tools
    Test and evaluate
    Define success and build evaluationsUsing the Evaluation Tool in ConsoleReducing latency
    Strengthen guardrails
    Reduce hallucinationsIncrease output consistencyMitigate jailbreaksReduce prompt leak
    Resources
    Glossary
    Release notes
    Claude Platform
    Console
    Log in
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Partners

    • Amazon Bedrock
    • Google Cloud's Vertex AI

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Help and security

    • Availability
    • Status
    • Support
    • Discord

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy
    First steps

    Get started with Claude Managed Agents

    Create your first autonomous agent.

    This guide walks you through creating an agent, setting up an environment, starting a session, and streaming agent responses.

    Core concepts

    ConceptDescription
    AgentThe model, system prompt, tools, MCP servers, and skills
    EnvironmentA configured container template (packages, network access)
    SessionA running agent instance within an environment, performing a specific task and generating outputs
    EventsMessages exchanged between your application and the agent (user turns, tool results, status updates)

    Prerequisites

    • An Anthropic Console account
    • An API key

    Install the CLI

    Check the installation:

    ant --version

    Install the SDK

    Set your API key as an environment variable:

    export ANTHROPIC_API_KEY="your-api-key-here"

    Create your first session

    All Managed Agents API requests require the managed-agents-2026-04-01 beta header. The SDK sets the beta header automatically.

    What's happening

    When you send a user event, Claude Managed Agents:

    1. Provisions a container: Your environment configuration determines how it's built.
    2. Runs the agent loop: Claude decides which tools to use based on your message
    3. Executes tools: File writes, bash commands, and other tool calls run inside the container
    4. Streams events: You receive real-time updates as the agent works
    5. Goes idle: The agent emits a session.status_idle event when it has nothing more to do

    Next steps

    Define your agent

    Create reusable, versioned agent configurations

    Was this page helpful?

    • Core concepts
    • Prerequisites
    • Install the CLI
    • Install the SDK
    • Create your first session
    • What's happening
    • Next steps
    1. 1

      Create an agent

      Create an agent that defines the model, system prompt, and available tools.

      set -euo pipefail
      
      agent=$(
        curl -sS --fail-with-body https://api.anthropic.com/v1/agents \
          -H "x-api-key: $ANTHROPIC_API_KEY" \
          -H "anthropic-version: 2023-06-01" \
          -H "anthropic-beta: managed-agents-2026-04-01" \
          -H "content-type: application/json" \
          -d @- <<'EOF'
      {
        "name": "Coding Assistant",
        "model": "claude-sonnet-4-6",
        "system": "You are a helpful coding assistant. Write clean, well-documented code.",
        "tools": [
          {"type": "agent_toolset_20260401"}
        ]
      }
      EOF
      )
      
      AGENT_ID=$(jq -er '.id' <<<"$agent")
      AGENT_VERSION=$(jq -er '.version' <<<"$agent")
      
      echo "Agent ID: $AGENT_ID, version: $AGENT_VERSION"

      The agent_toolset_20260401 tool type enables the full set of pre-built agent tools (bash, file operations, web search, and more). See Tools for the complete list and per-tool configuration options.

      Save the returned agent.id. You'll reference it in every session you create.

    2. 2

      Create an environment

      An environment defines the container where your agent runs.

      environment=$(
        curl -sS --fail-with-body https://api.anthropic.com/v1/environments \
          -H "x-api-key: $ANTHROPIC_API_KEY" \
          -H "anthropic-version: 2023-06-01" \
          -H "anthropic-beta: managed-agents-2026-04-01" \
          -H "content-type: application/json" \
          -d @- <<'EOF'
      {
        "name": "quickstart-env",
        "config": {
          "type": "cloud",
          "networking": {"type": "unrestricted"}
        }
      }
      EOF
      )
      
      ENVIRONMENT_ID=$(jq -er '.id' <<<"$environment")
      
      echo "Environment ID: $ENVIRONMENT_ID"

      Save the returned environment.id. You'll reference it in every session you create.

    3. 3

      Start a session

      Create a session that references your agent and environment.

      session=$(
        curl -sS --fail-with-body https://api.anthropic.com/v1/sessions \
          -H "x-api-key: $ANTHROPIC_API_KEY" \
          -H "anthropic-version: 2023-06-01" \
          -H "anthropic-beta: managed-agents-2026-04-01" \
          -H "content-type: application/json" \
          -d @- <<EOF
      {
        "agent": "$AGENT_ID",
        "environment_id": "$ENVIRONMENT_ID",
        "title": "Quickstart session"
      }
      EOF
      )
      
      SESSION_ID=$(jq -er '.id' <<<"$session")
      
      echo "Session ID: $SESSION_ID"
    4. 4

      Send a message and stream the response

      Open a stream, send a user event, then process events as they arrive:

      # Send the user message first; the API buffers events until the stream attaches
      curl -sS --fail-with-body \
        "https://api.anthropic.com/v1/sessions/$SESSION_ID/events" \
        -H "x-api-key: $ANTHROPIC_API_KEY" \
        -H "anthropic-version: 2023-06-01" \
        -H "anthropic-beta: managed-agents-2026-04-01" \
        -H "content-type: application/json" \
        -d @- >/dev/null <<'EOF'
      {
        "events": [
          {
            "type": "user.message",
            "content": [
              {
                "type": "text",
                "text": "Create a Python script that generates the first 20 Fibonacci numbers and saves them to fibonacci.txt"
              }
            ]
          }
        ]
      }
      EOF
      
      # Open the SSE stream and process events as they arrive
      while IFS= read -r line; do
        [[ $line == data:* ]] || continue
        json=${line#data: }
        case $(jq -r '.type' <<<"$json") in
          agent.message)
            jq -j '.content[] | select(.type == "text") | .text' <<<"$json"
            ;;
          agent.tool_use)
            printf '\n[Using tool: %s]\n' "$(jq -r '.name' <<<"$json")"
            ;;
          session.status_idle)
            printf '\n\nAgent finished.\n'
            break
            ;;
        esac
      done < <(
        curl -sS -N --fail-with-body \
          "https://api.anthropic.com/v1/sessions/$SESSION_ID/stream" \
          -H "x-api-key: $ANTHROPIC_API_KEY" \
          -H "anthropic-version: 2023-06-01" \
          -H "anthropic-beta: managed-agents-2026-04-01" \
          -H "Accept: text/event-stream"
      )

      The agent will write a Python script, execute it in the container, and verify the output file was created. Your output will look similar to this:

      I'll create a Python script that generates the first 20 Fibonacci numbers and saves them to a file.
      [Using tool: write]
      [Using tool: bash]
      The script ran successfully. Let me verify the output file.
      [Using tool: bash]
      fibonacci.txt contains the first 20 Fibonacci numbers (0 through 4181).
      
      Agent finished.
    Configure environments

    Customize networking and container settings

    Agent tools

    Enable specific tools for your agent

    Events and streaming

    Handle events and steer the agent mid-execution