Loading...
  • Messages
  • Managed Agents
  • Admin
Search...
⌘K
First steps
OverviewQuickstartPrototype in Console
Define your agent
Agent setupToolsMCP connectorPermission policiesAgent Skills
Configure agent environment
Cloud environment setupCloud container reference
Integration guideSecurity model
Delegate work to your agent
Start a sessionSession event streamSubscribe to webhooksDefine outcomesAuthenticate with vaults
Manage agent context
Access GitHubAttach and download files
Advanced orchestration
Multiagent sessions
Working with files
Files APIPDF supportImages and vision
Skills
OverviewBest practicesSkills for enterprise
MCP
Remote MCP servers
Claude on cloud platforms
Claude Platform on AWS
Log in
Integration guide
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
  • 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
  • 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
Managed Agents/Self-hosted sandboxes

Self-hosted sandboxes

Run agent sessions in your own self-hosted sandbox environment.

By default, Managed Agents executes tools and code inside Anthropic-managed cloud containers. Self-hosted sandboxes keep the orchestration on Anthropic's side but move tool execution into infrastructure you control, so the agent's code, filesystem, and network egress never leave your environment.

Self-hosted sandboxes are not yet available on Claude Platform on AWS.

How it differs from cloud environments

Cloud environmentSelf-hosted sandbox
Where tools runAnthropic-managed containersYour infrastructure
Network reachAnthropic's egress controlsYour network policy
File and GitHub repo mountingManaged by AnthropicManaged by you
LifecycleManaged by AnthropicManaged by you

Self-hosting is a good fit when the agent needs to operate on data that cannot leave your network boundary, reach internal services that are not publicly routable, or run under your organization's own compliance and audit controls.

When to combine with MCP tunnels

Self-hosting controls where the agent's code executes. MCP tunnels controls how Anthropic reaches MCP servers in your network. They are independent: a session running in Anthropic's cloud containers can still reach private MCP servers through a tunnel, and a self-hosted session can use either tunneled or public MCP servers. Use both when you want execution and tool access to stay inside your boundary.

Environment worker

The guide below describes how to build a worker with any generic sandboxing platform. Additional, platform-specific guides are available for Cloudflare, Daytona, Modal, and Vercel.

An environment worker is a process you run on your own infrastructure that receives tool execution requests from Anthropic and runs them locally. The self_hosted environment is a work queue connecting Anthropic's orchestration to your worker: when a session is assigned to an environment, Anthropic enqueues it as a work item. Your worker claims items from that queue, spawns an execution context for each session, downloads the agent's skills, runs tool calls locally, and posts results back.

Work is claimed by polling the environment's queue: either by an always-on worker that polls continuously, or a webhook-triggered handler that wakes on session.status_run_started and starts polling.

Both CLI and SDK include pre-built workers to orchestrate your sessions. The ant CLI supports the always-on pattern only; the SDK supports both always-on and webhook-triggered architectures.

The CLI and SDK both are configurable (see reference), but if you require more control, you can leverage the Environments Work endpoints directly and implement your own worker.

The SDK helpers require /bin/bash at that exact path. The TypeScript SDK additionally requires unzip, tar, and Node.js 22 or later. These dependencies are resolved at fixed paths and do not respect PATH overrides.

Sandbox filesystem

  • /workspace: the default working directory for tool execution and skill download. Skills are downloaded to /workspace/skills/<name>/. If you change --workdir from the default, update your agent's system prompt so Claude knows where to find them.
  • /mnt/session/outputs: the agent writes final output files to this path. When running in a container, mount a host directory here to retrieve them.

Start a session

Once your worker is running, create a session that targets the environment. Anthropic enqueues it and your worker claims and executes it.

File and GitHub resource mounting are handled in your container image rather than by Anthropic. To load your sandbox with session-specific files, you can pass session metadata when creating the session. Your orchestration layer can read that metadata and mount the relevant files before the worker starts executing.

session = client.beta.sessions.create(
    agent=agent.id,
    environment_id=environment.id,
    metadata={"input_file": "s3://my-bucket/data.csv"},
)

Memory is not yet supported with self-hosted sandboxes.

Reference

Monitoring and operations

These calls run from your monitoring or operations tooling, authenticated with your Claude API key, to observe and manage the worker fleet. The claim and keep-alive loop is handled inside the worker helpers, so you don't call those endpoints directly.

These endpoints authenticate with your organization API key, not the environment key. Call them from outside the worker host. Setting ANTHROPIC_API_KEY on the worker host exposes an organization-scoped credential to agent tool calls.

Read queue depth

work.stats returns the queue state for an environment:

  • depth is the number of items waiting to be claimed. Scale your worker fleet or alert on backlog based on this value.
  • pending is the number of items a worker has claimed and is currently processing.
  • oldest_queued_at is the timestamp of the oldest item in the queue, or null if the queue is empty.
  • workers_polling is the number of workers that have polled in the last 30 seconds. Use this for liveness alerting.
import os

import anthropic

client = anthropic.Anthropic()

stats = client.beta.environments.work.stats(os.environ["ANTHROPIC_ENVIRONMENT_ID"])
print(f"depth={stats.depth} pending={stats.pending}")
{
  "type": "work_queue_stats",
  "depth": 0,
  "pending": 0,
  "oldest_queued_at": null,
  "workers_polling": 0
}

Stop a session gracefully

Use work.stop to ask the worker handling a specific session to shut it down cleanly. The worker finishes any in-flight tool call, posts a final status, and releases the session. Pass force: true in the request body to interrupt immediately instead of waiting for the current tool call to complete.

Because these calls run from your operations tooling rather than the worker host, ANTHROPIC_WORK_ID isn't set automatically. Set it to the target work item's ID before running the examples below.

import os

import anthropic

client = anthropic.Anthropic()

work = client.beta.environments.work.stop(
    os.environ["ANTHROPIC_WORK_ID"],
    environment_id=os.environ["ANTHROPIC_ENVIRONMENT_ID"],
)
print(work.state)

Next steps

Managed Agent sessions

Create a session to run your agent and begin executing tasks.

MCP tunnels overview

Reach MCP servers inside your private network from any execution environment.

Security model

Understand the shared responsibility model for self-hosted sandbox environments.

Was this page helpful?

  • How it differs from cloud environments
  • When to combine with MCP tunnels
  • Environment worker
  • Sandbox filesystem
  • Start a session
  • Reference
  • Monitoring and operations
  • Read queue depth
  • Stop a session gracefully
  • Next steps