Why Run Coding Agents on a Server
- It keeps going: long tasks finish while your laptop is closed or offline.
- Reach it from anywhere: any device with SSH, a phone included, can check in on a session.
- A smaller blast radius: the agent sees the server's files and keys, not your personal machine's.
- Several at once: one tmux window per task or repository. More agents and bigger builds need more memory; a dedicated server gives a whole team fast cores nobody else shares.
1. Prepare the Server
After securing the server and setting up SSH keys, create a user for the agents and install the tools they will use:
sudo adduser dev sudo apt update && sudo apt install -y git tmux build-essential bubblewrap socat sudo -iu dev
bubblewrap and socat are what Claude Code's sandbox needs on Linux. Give this user a GitHub deploy key or a fine-grained token limited to the repositories the agents work on, not your personal key.
2. Install and Sign In to Claude Code
curl -fsSL https://claude.ai/install.sh | bash claude --version claude doctor # checks the installation
Run claude in a project folder. With no browser on the server, press c to copy the login link, open it on your own computer, and paste the code it shows at the Paste code here if prompted prompt. Claude Code needs a Pro, Max, Team, Enterprise or Console account. On Linux the credentials are kept in ~/.claude/.credentials.json, readable only by this user. The native install updates itself in the background (setup docs).
Turn on the sandbox with /sandbox inside Claude Code. It confines the shell commands the agent runs; file edits and web fetches still go through Claude Code's own permission checks (sandboxing docs).
3. Install and Sign In to Codex
curl -fsSL https://chatgpt.com/codex/install.sh | sh # or, with Node.js installed: npm install -g @openai/codex codex login --device-auth
Device-code sign-in is in beta and has to be allowed in your ChatGPT security settings or workspace permissions. Two other ways work on a server:
# Normal browser login, through an SSH tunnel from your computer: ssh -L 1455:localhost:1455 dev@203.0.113.10 codex login # open the printed address in your local browser # Or an API key: printenv OPENAI_API_KEY | codex login --with-api-key
Codex keeps its login in ~/.codex/auth.json in plain text unless you choose the system's credential store, so treat that file like a password. Its default sandbox, workspace-write, lets it edit the project and run routine commands there (Codex sandboxing).
4. Keep Sessions Running in tmux
tmux new -s app # start a named session cd ~/projects/app && claude # Ctrl+B then D detaches; the agent keeps working tmux ls # list sessions later tmux attach -t app # pick up where you left off
5. Run Tasks Without Watching
For scheduled or scripted work, both agents have a non-interactive mode. Claude Code takes a prompt with -p and the tools it may use without asking:
claude -p "Run the test suite and fix any failures" --allowedTools "Bash,Read,Edit"
Codex has codex exec for the same purpose. Run either from a systemd timer or a CI job; for CI on your own server, see self-hosted GitHub Actions runners.
Keep It Safe
- Keep the permission prompts. Claude Code's
bypassPermissionsmode and Codex'sdanger-full-accesssandbox are for throwaway servers or containers only. - Keep production secrets off this server; give the agent test credentials and a staging database.
- Back up your work: push branches often and keep server backups, so a bad command costs minutes, not days.
- Running models yourself instead of a hosted API? Pair the agents with a model on a GPU server or gpt-oss.
Claude, Claude Code, OpenAI, Codex and ChatGPT are trademarks of their respective owners. Virteche is not affiliated with or endorsed by them. Details about their products come from their public documentation as of the date at the top of this guide.