awslabs / awslabs/agentcore-samples
[example] Add Claude Managed Agents self-hosted sandbox on AgentCore Runtime
- Dominant language
- Python
- Stars
- 3.4k
- Forks
- 1.3k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 30
Description
## Proposed example
A new variant under `01-features/02-host-your-agent/01-runtime/04-coding-agents/` that runs Anthropic's [Claude Managed Agents (CMA) self-hosted sandbox](https://github.com/anthropics/claude-cookbooks/tree/main/managed_agents/self_hosted_sandboxes) on AgentCore Runtime.
## Why
The existing `04-coding-agents/` samples show two ways to host the Claude Code CLI on AgentCore Runtime (with S3 Files / EFS for persistent `/workspace`). They each implement their own HTTP loop and call `claude -p ...` directly.
Anthropic ships a separate, supported runtime called Claude Managed Agents. With CMA, Anthropic owns the agent loop, conversation state, skill download, prompt caching, and tool dispatch; the operator only owns the per-session sandbox compute. Anthropic's cookbook publishes reference implementations against Docker, Cloudflare Containers, Cloudflare Workers, Modal, Daytona, and Vercel — but not yet against AgentCore Runtime.
This example fills that gap. It maps 1:1 to Anthropic's own `docker/` variant (`docker run` -> `invoke_agent_runtime`, container -> microVM) using the session-affinity guarantee on AgentCore Runtime (`runtimeSessionId == ANTHROPIC_SESSION_ID`).
## Architecture (high level)
- Host runs `ant beta:worker poll` long-polling the Anthropic environment.
- Each claimed work item is forwarded to AgentCore via `invoke_agent_runtime`.
- Inside the microVM, an `@app.entrypoint` server spawns `ant beta:worker run` to attach to that one session's SSE and execute `bash`/`read`/`write`/`edit`/`glob`/`grep` tools in `/workspace`.
- PUBLIC network mode (no VPC, no NAT, no S3 Files) keeps the deploy minimal; existing variants 01- and 02- remain reusable on top of the same contract for persistent `/workspace`.
## What ships
A new directory `04-claude-managed-agents-self-hosted-sandbox/` with `bootstrap.py`, `setup.sh`, `deploy.py`, `cleanup.py`, `Dockerfile`, `server.py`, host-side bridge, and a step-by-step README that follows the tone of the existing `01-`/`02-` samples (Architecture, Prerequisites, Step-by-step, Sample prompts, Cleanup).
## Status
End-to-end verified on `us-west-2` with `claude-haiku-4-5`. PR to follow.
Contributor guide
Research direction
Read the existing 01- and 02- coding-agent samples and Anthropic's docker variant first. Then trace the proposed bootstrap.py, server.py, host-side bridge, deploy.py, setup.sh, Dockerfile, and README around ant beta:worker poll/run and invoke_agent_runtime. Done means the new sample deploys on AgentCore Runtime and forwards one session to the sandbox with the documented steps and prompts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, docker, python
- Domain
- ai, backend, cloud
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100