# Running a self-hosted worker Set up your self-hosted environment in three steps. These instructions are always available in your environment details. These instructions are pinned to the released SDK builds: Python `0.103.0`, TypeScript `0.97.0`, `ant` CLI v1.9.0. ## 0. Prerequisites All public-API calls below require: ``` anthropic-version: 2023-06-01 anthropic-beta: managed-agents-2026-04-01 ``` If you're reading this, you were already gated in by us to have access to all the APIs and Console functionality to use self-hosted workers for containers. If that is not the case please reach out to us so we can fix! ### SDKs: ``` # Python SDK uv pip install anthropic # TS SDK npm i @anthropic-ai/sdk ``` #### Using ant CLI for worker management Run this on the machine where you want the worker to run. It installs `ant`, which includes the worker that polls for jobs and executes them locally. Linux / macOS ``` VERSION=1.9.0 OS=$(uname -s | tr '[:upper:]' '[:lower:]') ARCH=$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/') curl -fsSL "https://github.com/anthropics/anthropic-cli/releases/download/v${VERSION}/ant_${VERSION}_${OS}_${ARCH}.tar.gz" \ | sudo tar -xz -C /usr/local/bin ant ant --version ``` ## 1. Creating a Self-hosted environment In Console → Workspace → Environments → New → Self-hosted Alternatively, create the self-hosted environment in-code: ``` client = anthropic.Anthropic(api_key=API_KEY) environment = client.beta.environments.create( name="self-hosted", config={"type": "self_hosted"}, ) ``` ``` const client = new Anthropic({ apiKey: API_KEY }); const environment = await client.beta.environments.create({ name: "self-hosted", config: { type: "self_hosted" }, }); ``` Generate an environment key. - In Console, open the environment and click Generate environment key. - Set it as `ANTHROPIC_ENVIRONMENT_KEY` on your runner host. - This key authenticates the whole worker flow — poll, ack, stop, heartbeat, the session event stream, and skill download — for that one environment. It is the only credential the worker needs. ## 2. Set your environment key Generate an environment key for this environment in the console. The key authenticates your infrastructure with this environment. Export it on the worker host: ``` export ANTHROPIC_ENVIRONMENT_KEY="sk-ant-oat01-..." ``` ## 3. Start the worker `ant beta:worker poll` runs a built-in loop that claims sessions assigned to this environment, executes tool calls (`bash`, `read`, `write`, `edit`, `glob`, `grep`) in `--workdir`, and posts results back. ``` ant beta:worker poll \ --environment-id "env_01..." \ --workdir "/workspace" ``` Every flag also reads from an environment variable, so a zero-flag invocation works for systemd or compose: ``` ANTHROPIC_ENVIRONMENT_ID=env_01... \ ANTHROPIC_ENVIRONMENT_KEY=sk-ant-oat01-... \ ant beta:worker poll --workdir /workspace ``` The worker exits cleanly on SIGTERM or SIGINT, draining in-flight tool calls before stopping. ### Spawning your own process per work item Pass `--on-work