Install & run Claude Code on a server or in Docker
// guide

How to install and run Claude Code on a server (or in a Docker sandbox), 24/7

Updated 2026-10-16

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

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.

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:

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

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:

you → claude code
“Fetch thevibehosting.com/SKILL.md, create a server there and install Claude Code on it for a non-root user. Help me verify my phone so the server can stay always-on.”

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.

you → your agent
“Fetch thevibehosting.com/SKILL.md and deploy it there”

No signup, no credit card. Your agent reads the skill, creates the server and ships your project. Full reference: API docs · SKILL.md.