Run Claude Code or Codex in the Cloud 24/7 on Your Own VM
To run Claude Code or Codex in the cloud around the clock, create a machine0 VM with a profile that carries your credentials, GitHub access and MCP servers, start the agent inside tmux, and reconnect from the CLI, the browser terminal or the iPhone app whenever you like. Idle detection suspends the VM when the work stops. A large VM (2 vCPU, 4 GB) costs about $38 per month always on, or about $9.15 for 8 hours a day over 22 workdays if you suspend it in between.
## Why run a coding agent on its own VM
Claude Code on your laptop stops when your laptop does. On a machine0 VM it keeps going: through a long refactor, overnight, while you are on a plane. Three things make a VM the right place for that work.
The first is persistence: no laptop lid, no sandbox session cap. The second is isolation: the agent has root on a machine that holds nothing of yours, so it can run whatever it decides to run and the worst case is a VM you destroy. The third is setup: an agent that boots without its API key, GitHub access or MCP servers spends its first ten minutes asking you for them. Profiles solve that.
This guide sets it up in seven steps. Every command is real, and every price is from the machine0 pricing table as of November 2026.
## Step 1: Install the CLI
$ curl -LsSf https://machine0.io/install.sh | shSign in when prompted. Your wallet needs a top-up before you can run more than one machine at a time (minimum $5, refundable if unused).
## Step 2: Connect Claude Code or Codex to a profile
Profiles are bundles of integrations, MCP servers, prompts and environment variables that machine0 injects into a VM when it is created. Connect Claude Code to the default profile:
$ machine0 integrations connect claude-code --profile defaultYou will be asked how Claude Code should authenticate. Choose one:
- An Anthropic API key, billed per token to your Anthropic account.
- An Anthropic subscription, logging in with your Claude Pro, Max or Team account.
Either way the credential is stored on the profile, not pasted into the VM by hand, and every VM created with the profile picks it up. Codex connects the same way:
$ machine0 integrations connect codex --profile default## Step 3: Connect GitHub, MCP servers and secrets
$ machine0 integrations connect github --profile defaultThis installs a GitHub App and lets you pick which repositories it can reach. The agent on the VM can then clone, branch, commit and open pull requests on those repos, and nothing else.
Add any remote MCP server the agent should see, plus the secrets its tools need:
$ machine0 integrations new linear --url https://mcp.linear.app/mcp --profile default
$ machine0 integrations connect linear --profile default
$ machine0 env set MY_SECRET_KEY=... --secret --profile defaultPrompts stored on the profile show up as slash commands in Claude clients:
$ machine0 prompts new build-feature --body @build-feature.md --profile defaultKeep one profile per project or agent role, and pass its name with --profile.
## Step 4: Create the VM with the profile
$ machine0 keys new agent-key --type MANAGED
$ machine0 new claude --profile default --size large --key agent-key \
--on-idle suspend --idle-timeout-minutes 60large is 2 vCPU, 4 GB RAM and an 80 GB disk at $0.052/hr. Pick xl (4 vCPU, 8 GB, $0.104/hr) or larger for heavy parallel work. The default image, ubuntu-24-04-loaded, comes with Docker, Node.js, Python, Go, Rust, Bun, Claude Code, Codex, OpenCode, tmux, zoxide, fzf, ripgrep and bat. If you prefer a declarative OS, use --image nixos-25-11-loaded.
The idle flags suspend the VM after 60 minutes of sustained inactivity (any value from 10 to 2,880). Idle detection needs a managed SSH key, which is why the first command creates one; it also turns on metrics and the browser terminal. Use destroy instead of suspend only for machines whose state you do not need, because destroy deletes the disk with no snapshot.
Provisioning takes minutes.
## Step 5: Run the agent in tmux
SSH in and start a tmux session before launching the agent, so it survives when you disconnect:
$ machine0 ssh claude
$ tmux new -s claude
$ git clone <your-repo>
$ cd <your-repo>
$ claudeClaude Code is already authenticated and has your GitHub access, MCP servers and prompts from the profile. Run codex instead in the same shell if you prefer. Give it the task and detach with Ctrl-b d. Close your terminal; the agent keeps working.
To check on it later:
$ machine0 ssh claude
$ tmux attach -t claude## Step 6: Reach it from your phone or the browser
-
The iPhone and iPad app has an SSH terminal. Set a startup command so opening the VM drops you straight into tmux:
$ machine0 update claude --ssh-client-initial-command "tmux attach || tmux new" -
The browser terminal in the dashboard at app.machine0.io uses a managed SSH key, so you can attach from any machine without carrying a private key around.
With metrics on, the dashboard shows CPU, load, memory and disk I/O graphs, and machine0 get claude --show-metrics prints the same data as sparklines. Either is a quick way to see whether the agent is still busy.
## Step 7: Get the work back, then suspend
Git is the obvious path: the agent commits and opens pull requests like a person would. For files outside git:
$ machine0 sync pull claude:~/app ./app
$ machine0 sync push ./app claude:~/app --watchA VM bills while it runs and while it is stopped. Suspend is what stops the compute bill, either through idle detection or by hand:
$ machine0 suspend claude
$ machine0 start claudeSuspend snapshots the disk and deletes the cloud instance. You pay only image storage, $0.078/GB/month, until you resume. It keeps the disk, not RAM or running processes: your repo and the agent's working files are there on resume, but the tmux session is not, so start it again. The VM also gets a new IP on resume, so update anything that pinned the old one.
To turn a configured machine into a template, stop it and run machine0 images new claude agent-base. Rotate secrets first: profile variables live on disk and are captured in the snapshot.
## Let agents manage their own machines
Give Claude Code on your laptop the machine0 MCP server and it can create a VM for a build, run commands on it and suspend it when done:
$ claude mcp add --transport http machine0 https://app.machine0.io/mcpProfile VMs already export MACHINE0_MCP_URL and MACHINE0_API_KEY, so an agent on one machine0 VM can create and control others. ssh_exec runs a command and returns stdout, stderr and the exit code; it needs a VM created with a managed key. The remote MCP server guide covers the full tool list and cost controls.
## What it costs
| Pattern | Size | Hours | Cost |
|---|---|---|---|
| Always on, whole month | large | 730 | About $38 |
| 8 hours a day, 22 workdays, suspended in between | large | 176 | About $9.15 |
| Always on, more headroom | xl | 730 | About $76 |
| A lightweight agent, always on | small | 730 | About $9.50 |
Add image storage for the time the VM is suspended. If a task is a single function call that finishes in seconds, a sandbox is cheaper to start; the comparison of sandboxes and persistent VMs covers that trade-off.
## FAQ
Do I need an Anthropic API key, or can I use my Claude subscription?
Either. When you connect claude-code to a profile you choose an Anthropic API key or an Anthropic subscription login (Claude Pro, Max or Team). Codex connects the same way.
What happens to a running Claude Code session when the VM is suspended?
It ends. Suspend snapshots the disk and deletes the cloud instance, so processes and tmux sessions do not survive. Files on disk do. On resume, open tmux and start Claude Code again.
What stops an agent from running up a bill overnight?
Create the VM with --on-idle suspend and an idle timeout between 10 and 2,880 minutes. After that much sustained inactivity the VM is suspended and compute billing stops. Resume it with machine0 start.
How do I get the work back to my machine?
Through git, since the GitHub App gives the VM push access to the repos you chose. For files outside git, machine0 sync pull copies a directory down over rsync, and sync push --watch mirrors a local folder up.
Can the agent create more VMs itself?
Yes. VMs created with a profile export MACHINE0_MCP_URL and MACHINE0_API_KEY, so an agent on one VM can call vm_create, ssh_exec and the other remote MCP tools to manage others.
Are secrets safe in a snapshot?
Profile variables are written to disk on the VM, so a snapshot contains them. Rotate any secret you would not want in an image before you run machine0 images new on that VM.