Self-hosted environments are in public beta on Team and Enterprise plans and are off by default. See Availability and limitations for the enablement path and what’s excluded.
claude --cloud, and scheduled routines, and by default they execute on Anthropic’s infrastructure. In a self-hosted environment, those same sessions execute inside your network, and the developer experience is otherwise the same apart from the differences in Availability and limitations and the deploy page’s known issues.
If your team doesn’t use cloud sessions, there’s nothing here to configure: sessions in a terminal or IDE always run on the developer’s own machine. If you want to run Claude Code on your own always-on machine and drive it from other devices, use Remote Control, which is also available on Pro and Max plans. When you’re ready to set up, go straight to the quickstart; to review the security posture first, start with Deploy to production. The rest of this page explains how self-hosting works and when to choose it.
How self-hosted environments work
Self-hosting has three parts:- Environment: a named destination that cloud sessions can be sent to. Your organization creates environments in claude.ai admin settings, and each one groups a set of runners.
- Runner: a program running on hosts inside your network. Runners execute the sessions; the idea is the same as a self-hosted CI runner.
- Session: one Claude Code task a developer started.
api.anthropic.com, with the short list of further hosts sessions can reach in Network requirements. Anthropic never connects into your network.
Availability and limitations
Check these before planning a rollout:- Plans: public beta for Team and Enterprise organizations. Self-hosted environments are off by default; an Owner or admin turns on Allow self-hosted environments on the Cloud environments admin page, which requires Claude Code on the web to be enabled for the organization.
- Zero Data Retention: unavailable for organizations with Zero Data Retention enabled.
- Model inference: sessions use the Anthropic API, and inference can’t be routed through Amazon Bedrock, Google Cloud’s Agent Platform, Microsoft Foundry, or an LLM gateway.
- Surfaces: sessions started from Claude Code on the web, the mobile and desktop apps, scheduled routines, and the terminal, with
claude --cloudor a scripted--environmentdispatch, can run in self-hosted environments. Claude Tag, Claude Security, and Code Review sessions don’t route to them yet; support for those surfaces follows separately. - Repositories: sessions check out repositories from GitHub; see GitHub authentication options.
- Billing: sessions in a self-hosted environment consume your organization’s Claude Code usage the same way sessions in Anthropic-hosted environments do.
Why self-host
Most teams are better served by Anthropic-hosted environments, which need no infrastructure to run or maintain. Self-hosting is for teams whose network, tooling, or compliance requirements call for keeping session execution on infrastructure they control. If that’s you, plan for the operational ownership it carries: you build and maintain the runner image, operate the fleet, and control its network. In exchange, self-hosting gives you network access, custom tooling, and compliance control:- Network access: sessions run inside your network and can reach internal services, databases, and registries without exposing them to the public internet
- Custom tooling: pre-install compilers, SDKs, and internal CLIs in your runner image so every session starts ready to build
- Compliance: repository checkouts and build artifacts stay on infrastructure you control. Session content still goes to
api.anthropic.comfor model inference.
Environments, runners, and sessions
Environments are managed on the Cloud environments page in claude.ai admin settings; runners are processes you start and manage on your own infrastructure.Key concepts
These terms appear throughout the self-hosted pages:
In API fields, token claims, and metric names, the environment appears as
pool, and the environment ID is the pool_id. The reference maps the two spellings, including the deprecated pool flag names.
A runner serves one user at a time. The first session a runner picks up locks the runner to that user, and the runner then runs sessions only for that user, up to a configured capacity. The minimum fleet size is therefore the number of users you expect to be active at once.
Session lifecycle
When a developer starts a session and selects your environment, Anthropic’s control plane places the session on the environment’s queue. From there:- A runner with free capacity claims the session and holds a lease on it.
- The runner clones the repository into its working directory and spawns a child Claude Code process.
- The child streams events back over HTTPS while the runner keeps polling; each poll refreshes the lease and doubles as the heartbeat.
- If the runner stops polling for about 60 seconds, the server requeues the session for another runner.
Runner lifecycle
The first session a runner picks up locks the runner to the account of the user who started that session, and the runner runs up to--capacity concurrent sessions for that account. While the runner has active sessions, the runner keeps claiming the locked account’s queued work. What happens once they finish depends on --drain-grace-sec:
- At the default of
0: the runner exits as soon as its active sessions finish, without polling for more, so the orchestrator you deploy it under, such as Kubernetes, can restart it with a fresh disk, ready to serve any account. - At a positive value: the runner keeps polling the locked account’s queue for that many seconds before exiting.
SIGTERM needs no flag: the runner drains as Shutdown timing describes. If your infrastructure instead destroys hosts at a known wall-clock time without a signal, or with a grace period too short to drain, such as a sandbox lifetime cap or spot-instance reclamation, pass --retire-at <epoch-seconds> set to a few minutes before that time. At the retire time:
- The runner stops taking new work.
- The runner releases each active session through the same release path the
--release-idle-session-minflag uses, so the session resumes on a fresh runner when the user sends their next message. A session that’s mid-turn is released as soon as that turn finishes; a session whose finished turn left background tasks running gets up to 60 seconds of grace before releasing anyway. - The runner exits 0 once all its sessions are released.
--retire-at, a signal-less host kill is indistinguishable from a crash: the control plane records a lost worker rather than a clean release, and the session requeues to another runner.
Network paths
The runner and its sessions make several kinds of outbound connection, and no inbound connectivity from Anthropic is required:- Control plane: the runner polls
api.anthropic.comfor work and posts setup-progress and failure events, all outbound HTTPS. Polling doubles as the runner’s heartbeat. - SCM connector: the optional orchestrator SCM connector tunnel is the only WebSocket connection.
- Git: the runner clones from and pushes to your git host over HTTPS or SSH, authenticated with credentials your deployment provides; Configure git covers the options, including per-session minted credentials and the Anthropic git proxy, which routes git through
api.anthropic.cominstead. - Session child: the child Claude Code process holds the session’s event stream to
api.anthropic.com, and makes its own outbound calls for model inference and for git commands run during the session. See Network requirements for the full egress list. The diagram above shows these paths, apart from the optional SCM connector.
HTTPS_PROXY and NO_PROXY; set them in each process’s environment. The variables cover control-plane calls, the orchestrator’s SCM connector WebSocket, and the built-in clone for HTTPS remotes, and sessions inherit them from the runner. Session streaming uses server-sent events over HTTPS, so a proxy in the path must not buffer responses.
What stays on your infrastructure
Repository checkouts, build artifacts, secrets, and any files a session creates or modifies stay on the machines you provision. The conversation itself, including prompts, responses, and tool results, goes toapi.anthropic.com for model inference, and the session transcript is stored by Anthropic so a session can be picked up from any surface.
Session orchestration, queueing, and the claude.ai interface remain Anthropic-hosted: a self-hosted environment moves session execution into your network, not the control plane.
Get started
The self-hosted environments pages are organized by what you’re doing:- Quickstart: install Claude Code, create an environment, start a runner, and route your first session
- Deploy to production: security hardening, network egress, git credentials, Kubernetes and Compose recipes, known issues, and troubleshooting
- Customize sessions: wrapper scripts for per-session credentials, lifecycle hooks, on-demand runners, MCP servers, and permissions
- Test end to end: a CI smoke test that verifies a runner image before you promote it
- Reference: every CLI flag, environment variable, metric, and the health endpoint
- Verify session identity: validate the session token from your own services before granting access