Claude Managed Agents worker

Anthropic's Claude Managed Agents can run with a self-hosted environment. The agent loop stays on Anthropic's side, and the tools run on a machine you control: bash, the file tools (read, write, edit, glob, grep) and code. A worker on that machine long-polls Anthropic's work queue. The connection is outbound only, so nothing dials into the machine.

The managed-agents template is that machine. It is the base Linux desktop with Anthropic's Python SDK worker (EnvironmentWorker) installed as a service, waiting for your environment's key.

What is on the image

sh systemctl status mandala-managed-agents-worker journalctl -u mandala-managed-agents-worker -f

Without its two values the worker exits at once with "not connected". The service does not restart it in a loop.

Connect it

  1. Create a self-hosted environment with your Anthropic API key:

python import anthropic

client = anthropic.Anthropic() environment = client.beta.environments.create( name="mandala", config={"type": "self_hosted"} ) print(environment.id) # env_...

  1. In Console, open that environment and generate an environment key (sk-ant-oat01-…).
  1. Store both as Mandala secrets and bind them to the computer as ANTHROPIC_ENVIRONMENT_KEY and ANTHROPIC_ENVIRONMENT_ID. A bound value is delivered before the desktop and the worker start, and Mandala keeps it on a memory-backed file system in the guest, not on the disk. The image holds no key.
  1. Create sessions against environment_id exactly as you would for a cloud environment:

python session = client.beta.sessions.create( agent={"type": "agent", "id": agent.id, "version": agent.version}, environment_id=environment.id, )

Launch the worker computer

This program needs pip install mandala-computer and a MANDALA_API_KEY. It stores the two values as secrets, launches a worker computer with them bound, and checks that the worker is polling. The computer is persistent: it keeps serving your environment until you stop or delete it.

The stored secrets are named after the environment, and bound under the two names the worker reads. A stored secret is shared by every computer bound to it, so one fixed name for every environment would repoint an earlier worker at the newest environment on its next start.

import os

from mandala_computer import Client

client = Client()  # reads MANDALA_API_KEY
environment_id = os.environ["ANTHROPIC_ENVIRONMENT_ID"]  # env_...
key = client.secrets.set(f"ANTHROPIC_ENVIRONMENT_KEY_{environment_id}", os.environ["ANTHROPIC_ENVIRONMENT_KEY"])
env_id = client.secrets.set(f"ANTHROPIC_ENVIRONMENT_ID_{environment_id}", environment_id)

computer = client.computers.launch(
    template="managed-agents",
    name="managed-agents-worker",
    secrets=[
        {"secret_id": key.id, "env": "ANTHROPIC_ENVIRONMENT_KEY"},
        {"secret_id": env_id.id, "env": "ANTHROPIC_ENVIRONMENT_ID"},
    ],
)  # waits until the secrets have reached the computer
res = computer.exec(
    "systemctl is-active mandala-managed-agents-worker; "
    "journalctl -u mandala-managed-agents-worker -n 3 --no-pager -o cat",
    desktop=True,
)
print(computer.id, res.stdout_text)  # "active" and "polling environment env_..."

To bind the values to an existing computer, stop it first, bind them, and start it again. The worker reads them when it starts.

What to know before you rely on it