Run Claude Code in Containers | Generated by AI

Home 2026.02

Question: How to run Claude code (Claude Code interpreter/agent) in a container or cloud server?

Answer:

Claude Code (Anthropic’s terminal-based AI coding agent / code interpreter tool) is commonly run inside Docker containers for safety and isolation. This is the officially recommended approach in many cases because Claude Code can execute arbitrary code, install packages, run servers, etc.

Here are the main practical ways people run it in 2026 (local container or cloud / VPS):

Docker introduced built-in support for running coding agents like Claude Code in isolated sandboxes.

# Make sure you have recent Docker installed
docker sandbox run claude ~/my-project

You can also pass a prompt directly:

docker sandbox run claude -- "refactor this API client to use async/await"

Works on Mac, Windows, Linux.

Most developer-oriented way:

  1. Install Docker Desktop + VS Code + Dev Containers extension
  2. Use Anthropic’s official template or community ones:
    • https://github.com/anthropics/claude-code (look for .devcontainer folder)
    • Many community forks / templates exist (search “claude code devcontainer”)
  3. Open folder → “Reopen in Container”
  4. Claude Code runs inside the container with strong isolation
  5. You can give --dangerously-skip-permissions for fully autonomous mode

This setup is frequently used for long-running agents.

3. Plain Docker container (DIY / cloud VPS friendly)

Minimal example Dockerfile:

FROM ubuntu:24.04

RUN apt-get update && apt-get install -y curl git build-essential
RUN curl -fsSL https://claude.ai/install.sh | bash

# Optional: install common tools Claude Code likes
RUN apt-get install -y python3 python3-pip nodejs npm

WORKDIR /workspace

CMD ["claude"]

Build & run:

docker build -t claude-code .
docker run -it --rm \
  -v "$(pwd)":/workspace \
  -e ANTHROPIC_API_KEY=sk-ant-... \
  claude-code

On a cloud VPS (RunPod, Hostinger, AWS EC2, DigitalOcean, etc.):

4. Cloud-specific / managed sandbox options

5. If you want fully local models (no Anthropic API)

Some people replace the Anthropic backend with local models via Docker Model Runner or Ollama + Anthropic-compatible endpoint:

ANTHROPIC_BASE_URL=http://localhost:12434 claude --model your-local-model ...

But most people still use real Claude models (Sonnet 3.7 / Opus 4 / etc.) via API key.

Security note: Always run Claude Code in a container — never directly on your main machine with dangerous flags, especially if giving it long-running / autonomous tasks.

Choose method depending on your goal:

References:


Back Donate