> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mirage.strukto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Managed Agents

> Make a Mirage workspace the self-hosted environment of an agent on Claude Managed Agents.

[Claude Managed Agents](https://platform.claude.com/docs/en/managed-agents/overview) runs the agent on Anthropic's servers. In a [self-hosted environment](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes), a worker you run answers its `bash`, `read`, `write`, `edit`, `glob` and `grep` calls. `mirageTools(ws)` gives that worker Mirage's versions, so every call runs in the workspace, under its profile, mounts and policies. The worker only connects out to Anthropic, so it can run inside your own server.

## Install

```bash theme={null}
npm install @struktoai/mirage-claude-managed-agents @struktoai/mirage-node @anthropic-ai/sdk
```

## Run a worker

The workspace here keeps its files in Redis next to RAM, which needs a Redis server and the `redis` package:

```bash theme={null}
docker run -d -p 6379:6379 redis
npm install redis
```

Create a self-hosted environment and an agent with the `agent_toolset_20260401` toolset as [Anthropic's guide](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes) shows, then serve its sessions from the workspace:

```ts theme={null}
import Anthropic from '@anthropic-ai/sdk'
import { MountMode, RAMVFS, RedisVFS, Workspace } from '@struktoai/mirage-node'
import { mirageTools } from '@struktoai/mirage-claude-managed-agents'

const ws = new Workspace(
  { '/workspace': new RAMVFS(), '/redis': new RedisVFS({ url: 'redis://localhost:6379' }) },
  { mode: MountMode.WRITE },
)

const worker = new Anthropic().beta.environments.work.worker({
  environmentId: process.env.ANTHROPIC_ENVIRONMENT_ID!,
  environmentKey: process.env.ANTHROPIC_ENVIRONMENT_KEY!,
  tools: mirageTools(ws),
})
await worker.run()
```

## How it behaves

* The tools keep the toolset's names. One the session's [profile](/home/policy/overview) would always refuse is left out: a read-only workspace gets no `write` or `edit`.
* `bash` runs Mirage's shell, so a line sees the workspace's mounts and commands, not the worker's machine. A `restart` is refused, since the session keeps its directory and variables. A relative path resolves against the session's working directory, which `cd` moves.
* `write` overwrites a file only after the agent read all of it, and `write` and `edit` refuse a file that changed since the agent read it. `staleWriteProtection: false` turns that off.
* `sessionId` runs the tools as another session, with its profile.
* `web_search` and `web_fetch` still run on Anthropic's servers. Turn them off in the agent's toolset to keep the agent to the workspace.

## Example

[`examples/typescript/agents/claude_managed_agents/redis_report.ts`](https://github.com/strukto-ai/mirage/blob/main/examples/typescript/agents/claude_managed_agents/redis_report.ts) creates the agent and a session, serves the session from a RAM and Redis workspace, asks the agent to total `/workspace/orders.csv` into `/redis/report.md`, and prints the report from Redis.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.