How to run Claude Code locally with self-hosted containers
Deploy Claude Code v1.4.0 execution environments to your own infrastructure to secure agent workflows and reduce file operation latency.
Anthropic’s release of Claude Code v1.4.0 introduces a decoupled container architecture that lets you run Claude Code sessions on your own compute. By moving the execution environment out of Anthropic’s managed remote sandboxes and into your own infrastructure, you keep proprietary source code and execution logs entirely within your network. This deployment model shifts the security boundary for remote code execution risks to your controlled environment while reducing latency for file-heavy agent tasks.
Previously, the agentic command-line tool relied exclusively on ephemeral execution environments hosted by Anthropic. The new orchestration layer separates the CLI from the sandbox where terminal commands, code compilation, and testing occur.
Architecture and Deployment Options
Self-hosted execution works by pairing your local Claude Code CLI with a remote container endpoint. Anthropic provides official integration templates for multiple infrastructure environments:
- Docker: Designed for individual developer workstations and localized testing.
- Kubernetes (K8s): Intended for enterprise teams requiring scalable, orchestrated execution clusters.
- AWS ECS and Google Cloud Run: Managed container service templates for cloud-native development workflows.
Running these sessions internally limits external data exposure. For organizations in defense, healthcare, and finance, this addresses primary data residency blockers and simplifies the process of implementing agentic security controls around proprietary codebases.
System Requirements and Licensing
While the Claude Code CLI itself remains available via npm, configuring the self-hosted backend orchestration for production team-wide use cases requires an active Claude Enterprise plan subscription.
Code session containers require adequate compute to handle the overhead of running full build tools, language servers, and test suites. The recommended minimum specification for a single code session container is:
- Compute: 2 vCPUs
- Memory: 4GB RAM
Allocating fewer resources can result in timeouts when the agent attempts to compile large projects or execute intensive dependency installations.
Configuring Remote Execution
To route your agent sessions to your custom infrastructure, use the --remote-host flag when initializing the CLI. You pass the URL of your deployed container instance directly to the command:
bash
claude-code —remote-host
The CLI authenticates with the remote host and establishes a persistent connection for the duration of the session. All terminal operations, file system reads, and process executions requested by the LLM are then routed through this connection to your container rather than Anthropic’s servers.
For the exact Dockerfiles and Kubernetes manifests needed to provision the endpoint matching the <url> parameter, consult the official documentation provided in your Claude Enterprise console.
Security and Performance Tradeoffs
Self-hosting the execution layer introduces distinct advantages and operational responsibilities.
Security teams monitoring AI agents have highlighted that this architecture effectively mitigates concerns regarding prompt injection attacks leading to Remote Code Execution (RCE) on Anthropic’s shared infrastructure. By adopting a zero trust agent model, the impact of a compromised agent is strictly contained within your specific Virtual Private Cloud (VPC) or local sandbox.
From a performance perspective, bringing compute closer to the data improves execution speeds. Running the session on the same local network or VPC as the developer workstation yields a 15-20% reduction in latency for file-heavy operations. Commands like npm install or massive multi-file refactors execute significantly faster when they do not have to traverse the public internet to sync state with Anthropic’s managed sandboxes.
However, this model requires your internal DevOps or platform engineering teams to manage container lifecycle, resource scaling, and image updates. You are responsible for ensuring the container images remain patched and that the agent environments do not maintain persistent state between distinct tasks unless explicitly designed to do so.
Integrate this self-hosted capability into your existing CI/CD pipelines to manage Claude Code workflows securely. Ensure your container orchestrator is configured to spin down idle instances to optimize resource consumption across your development team.
Get Insanely Good at AI
The book for developers who want to understand how AI actually works. LLMs, prompt engineering, RAG, AI agents, and production systems.
Keep Reading
Model-Agnostic Cloud Runtime for Coding Agents Secures $7M Seed
Niteshift exited stealth with $7 million in funding to provide enterprises a model-agnostic infrastructure layer for executing and verifying AI-generated code.
How to Control Token Budgets in Claude Code via Effort Levels
Learn how to configure model selection and the new effort parameter in Claude Code to optimize token spend and agentic task thoroughness.
How to Manage Claude Code Workflows via CLAUDE.md
Learn how to control Claude Code's agentic behavior using CLAUDE.md files, reusable skills, lifecycle hooks, and isolated subagents.
How to build an iOS app with Claude Code subagents
Learn how to orchestrate parallel subagents in Claude Code to build and ship a production Swift application using natural language and specialized roles.
How to Integrate Claude Code into Large Legacy Codebases
Learn how to integrate Claude Code into massive legacy projects using incremental context and the new native binary features in version 2.1.119.