How to install and run Claude Code on a server (or in a Docker sandbox), 24/7
Claude Code on your laptop stops when the lid closes. On a server it can keep working while you're away — running long refactors, tests, scheduled jobs or an agent loop — and in a sandbox it can do that without access to your personal machine. This guide covers installing it on Linux, running it in Docker, logging in on a headless box and keeping it alive. If you just want a ready server, there's a free one at the end.
1. Install Claude Code
Native installer (Linux, macOS, WSL) — recommended
curl -fsSL https://claude.ai/install.sh | bash
It installs the claude command for the current user. When it finishes, open a new shell (or reload your
profile) so the command is on your PATH, then check it:
claude --version
npm
If you already manage tools with Node.js, install the package globally. You need a recent Node.js (18 or newer):
npm install -g @anthropic-ai/claude-code
Avoid sudo npm install -g; if you get permission errors, point npm's global prefix at a directory in
your home folder or use a Node version manager instead.
Windows (PowerShell)
irm https://claude.ai/install.ps1 | iex
2. Notes for Linux and Ubuntu servers
- Install the basics first. Claude Code is most useful when it can use the tools your project needs:
sudo apt update && sudo apt install -y git curl, plus your language toolchain. - Use a normal user, not root. Create one for the agent (
sudo adduser agent), install Claude Code as that user, and give it only the access it needs. If the agent goes wrong, it can only damage what that user can touch. - RAM matters more than CPU. The agent itself is light; builds, test runs and dev servers it starts are not. 1 GB is a comfortable start for typical web projects.
- Keep the project in Git and let the agent commit to a branch, so every change is reviewable and reversible.
3. Log in on a headless server
A server has no browser, and that's fine. Run claude and choose a login method: it shows a link you open in
a browser on any device — your laptop or phone — and you complete the sign-in there. Alternatively, Claude Code can use an
Anthropic API key from the ANTHROPIC_API_KEY environment variable, billed to your API account.
- Keep keys in a file only your user can read (
chmod 600), not in the project or in Git. - Use your own account and don't share it — on a server, it's easy to forget who else has a shell there.
4. Why sandboxing matters for an autonomous agent
Claude Code runs real shell commands. Interactively, it asks before doing anything risky. On a server you often want it to run unattended — and that's exactly when the machine it runs on matters:
- Blast radius. On your laptop the agent can reach your SSH keys, browser sessions, cloud credentials and every repository you have. In a sandbox it can reach only what you put there.
- Prompt injection. An agent that reads web pages, issues or dependencies can be steered by text hidden in them. A sandbox limits what a hijacked session can do.
- Skipping permission prompts. Claude Code has a well-known
--dangerously-skip-permissionsflag for fully unattended runs. The name is the warning: only use it in a disposable, isolated environment, never on a machine with anything you can't afford to lose. - Scoped credentials. Give the sandbox a fine-grained token for one repository rather than your personal keys.
5. Run Claude Code in a Docker container
A container is the quickest local sandbox. A minimal image using the npm package:
FROM node:20
RUN npm install -g @anthropic-ai/claude-code
RUN useradd -m agent
USER agent
WORKDIR /work
CMD ["bash"]
docker build -t claude-sandbox .
docker run -it --rm -v "$PWD":/work claude-sandbox
# inside the container:
claude
- Mount only the project folder. Never mount your home directory,
~/.sshor the Docker socket. - Remember the agent can change everything in the mounted folder — commit before you start.
- Anthropic's Claude Code documentation also describes a reference dev container setup with stricter network rules, if you want a more locked-down starting point.
- A regular container shares the host's kernel. For stronger isolation, run it on a separate machine or in a sandboxed runtime such as gVisor.
6. Keep it running 24/7
If you start Claude Code in a plain SSH session, it dies when the connection drops. Run it inside tmux instead:
sudo apt install -y tmux
tmux new -s claude # start a session, then run: claude
# detach: press Ctrl-b, then d — Claude Code keeps working
tmux attach -t claude # reconnect later, from anywhere
For recurring, non-interactive work, Claude Code's print mode runs a single prompt and exits, which fits cron:
claude -p "run the test suite and summarize failures". And the server itself has to stay up — a machine that
sleeps or shuts down takes the agent with it.
7. A free root sandbox for Claude Code
The Vibe Hosting gives you exactly this environment: an Ubuntu server in its own gVisor sandbox, with root, persistent disk and an HTTPS address, created with one API call — no signup, no card. Paste this to the Claude Code you already have, and it sets up a second one on the server:
- Servers sleep after about 10 minutes without incoming traffic. For an agent that works while you're away, mark the server always-on — that needs a verified phone.
- A 512 MB server runs 24/7 inside the free monthly credit; 1 GB always-on is about $1.35 a month after it. See pricing.
- Then SSH in, attach to tmux and log in to Claude Code as described above. Anything it builds can be served straight from the same box — see Claude Code hosting.
Related: sandbox and hosting for AI agents · deploy from Claude Code · the best MCP servers for Claude Code.
FAQ
How do I install Claude Code on Linux or Ubuntu?
Run the native installer: curl -fsSL https://claude.ai/install.sh | bash. If you prefer npm, use npm install -g @anthropic-ai/claude-code with Node.js 18 or newer. Then run claude in your project folder.
Can Claude Code run in a Docker container?
Yes. Install it in the image (for example with npm), run the container as a non-root user and mount only your project folder. A container is a good sandbox for unattended runs.
How do I log in to Claude Code on a server without a browser?
Run claude and pick a login method; it gives you a link to open in a browser on any other device. You can also provide an Anthropic API key through the ANTHROPIC_API_KEY environment variable.
How do I keep Claude Code running after I close SSH?
Start it inside tmux and detach with Ctrl-b d. Reattach later with tmux attach. The server itself must stay on.
Is there a free server for running Claude Code?
The Vibe Hosting gives you a free gVisor-sandboxed Ubuntu server with root, no signup or credit card. With a verified phone a 512 MB server can run 24/7 inside the free monthly credit.
Try it: paste this to Claude Code, Cursor or Codex.