Messages API, Agent SDK, Claude Code or Managed Agents: where should your agent run?

Four ways to run a Claude agent compared by who runs the loop, where tools execute and who keeps state, with a decision path for CCAR-P scenarios.

· 4 min read · CCAR-P · UpHopp team

The question behind the choice

The same Claude model can sit behind very different runtimes. What changes is who runs the agent loop, where tools and files live, and who keeps the state and recovers when something fails. The CCAR-P guide tests this directly, as deployment surface and agent runtime selection, and many integration scenarios depend on it too.

Four options side by side

Who runs the loopWhere tools runTypical fit
Messages API (client SDK)Your code: you send tool results back each turnYour application for client tools; Anthropic for server tools such as web searchCustom loops and existing services that need full control
Claude Agent SDKA library in a process you operate, running Claude Code's agent harnessThat process: built-in tools, hooks, permissions, subagents and MCPEmbedding an agent in your own Python or TypeScript application
Claude Code headless (claude -p)The Claude Code CLI, as a subprocess or a CI stepThe machine or runner it runs onScripts, scheduled jobs and CI pipelines
Claude Managed AgentsAnthropic's hosted agent harnessAn Anthropic-managed cloud sandbox, or a self-hosted sandboxLong-running, asynchronous or scheduled work with little infrastructure

When the Messages API is enough

If the job is a single request, or a loop you already run inside a service, call the Messages API directly. You own the loop: when Claude returns a tool_use block, your code runs the tool and sends the result back in the next user message, with the tool_result blocks first. You also own conversation history, retries and timeouts.

This gives you the most control, and it keeps tools that must stay inside your network where they are. The cost is that everything a harness would give you, such as file tools, permissions and session storage, is yours to build.

When to embed the Agent SDK

The Agent SDK is Claude Code's agent as a library. It runs the Claude Code binary inside a process you operate and gives you its capabilities: built-in tools for files, commands and search, hooks at points in the agent lifecycle, permission rules, subagents, MCP connections, and sessions you can resume or fork.

Choose it when the agent has to run next to your own data, binaries or network, and you don't want to write the tool loop yourself. You still operate the process, so scaling, monitoring and recovery are your team's job.

When headless Claude Code fits

Running claude -p turns Claude Code into a non-interactive command for scripts and CI. It exits with 0 on success and a non-zero code on failure, and --output-format json returns the result with metadata, including total_cost_usd, so a pipeline can branch on the outcome and track spend.

When Managed Agents fits

Claude Managed Agents hosts the harness for you. You define an agent (model, system prompt, tools, MCP servers and skills) and an environment, then start sessions and exchange events with them. Sessions are stateful: they keep a persistent filesystem and conversation history, so a long task can run for minutes or hours and a later request can continue the same session.

  • Vaults hold credentials. The sandbox sees only a placeholder, and the real secret is substituted at egress for the hosts you allow, so clients that sign requests locally, such as AWS SigV4, don't work with them.
  • A session budget sets a hard ceiling on one session's list cost.
  • Scheduled deployments run agents on a cron schedule.
  • Sandboxes can be self-hosted for compliance or data-residency needs, and the whole service can be self-hosted.

Two constraints matter in architecture reviews. First, Managed Agents is in beta, and the hosted service isn't eligible for zero data retention because transcripts persist until you delete them; a self-hosted deployment is the exception. Second, it runs on the Claude API, Claude Platform on AWS and Anthropic-managed Claude on Google Cloud, but not on Amazon Bedrock or Microsoft Foundry.

A quick decision path

  1. Must the tools touch files, binaries or systems that can't leave your environment? Use the Agent SDK or headless Claude Code there, or Managed Agents with a self-hosted sandbox.
  2. Is a zero data retention arrangement a hard requirement? Hosted Managed Agents is out; self-hosted Managed Agents or your own loop remain.
  3. Does the team want to avoid running the agent loop and sandbox at all? Managed Agents is built for that.
  4. Is it a job in an existing scheduler or CI runner? Headless Claude Code fits the runner you already have.
  5. Do you need a custom loop with full control over every turn? Use the Messages API.

Official references

Put it into practice

Try Claude CCAR-P questions for free

Scenario questions with an explanation for every option, then timed mocks when you're ready.

Try free practice