# Run Claude Code in a cloud VM

> Create a cloud Ubuntu VM with Claude Code already installed, give it your Anthropic key, then prompt it from your laptop or SSH in and run claude. The VM keeps working when your laptop sleeps, and stopping it saves memory so the session resumes where it left off.

Source: https://sandboxer.com/guides/run-claude-code-in-a-cloud-vm. Updated 2026-10-24.

**Short answer:** Create a cloud Ubuntu VM with Claude Code already installed, give it your Anthropic key, then prompt it from your laptop or SSH in and run claude. The VM keeps working when your laptop sleeps, and stopping it saves memory so the session resumes where it left off.

## At a glance

| Topic | Detail |
| - | - |
| What you get | A Cloud Hypervisor microVM: Ubuntu 24.04, root via `sudo`, systemd, Docker, `/dev/kvm` |
| Claude Code | Preinstalled in every sandbox (also Codex, OpenCode, Pi, Kimi Code, Mistral Vibe) |
| Credentials | Your own Anthropic API key, added once on the dashboard's **Agents** page |
| Size used below | `default`: 4 vCPU, 8 GB RAM, 50 GB disk, $0.036/hour, billed per second |
| When it's stopped | Costs nothing; resume brings back memory and running processes |
| Previews | Any port becomes an HTTPS URL with `sbx host` |

## 1. Install the CLI and sign in

```bash
curl -fsSL https://sandboxer.com/install | sh
```

The installer puts `sbx` on your `PATH` and runs `sbx onboard`, which signs you in through the browser. New accounts start a 7-day trial with 25 hours of machine time (card required). On Windows, use `irm https://sandboxer.com/install.ps1 | iex`.

## 2. Add your Anthropic key

Open the dashboard's **Agents** page and add an Anthropic API key. Sandboxes started from your environment get it automatically, so Claude Code is signed in when the VM starts. For this integrated agent, sign-in with a Claude subscription isn't supported yet, so use an API key. (In your own SSH session, `/login` works as usual; see step 4.)

If you start a sandbox with `--no-env` (none of your secrets), pass a key just for that sandbox instead:

```bash
sbx new --no-env -e ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY"
```

## 3. Create the VM

```bash
sbx new
```

It's ready in seconds and prints the sandbox id (like `sb_k3v9x2mq`), its URL and its size. Check that Claude Code is there:

```bash
sbx exec sb_k3v9x2mq "claude --version"
```

## 4. Give Claude Code work

**From your laptop, without a terminal session.** `sbx prompt` sends a task to the agent inside the VM and returns at once. The agent runs in `/home/user` with the sandbox's environment.

```bash
sbx prompt sb_k3v9x2mq --provider claude-code "Clone github.com/acme/api, run the tests and fix the failures"
sbx events sb_k3v9x2mq --follow     # stream what it's doing
sbx steer sb_k3v9x2mq "Skip the integration tests"
```

The same call is a plain HTTP request, so a script or another agent can do it:

```bash
curl -sS -X POST https://sandboxer.com/api/v1/sandboxes/sb_k3v9x2mq/prompt \
  -H "Authorization: Bearer $SANDBOXER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"provider":"claude-code","prompt":"Run the tests and fix the failures"}'
```

**Interactively, the way you use it locally.** SSH in and start `claude`. `tmux` is installed, so the session survives a dropped connection.

```bash
sbx ssh sb_k3v9x2mq
tmux new -s claude
claude
```

If Claude Code says `Not logged in · Please run /login`, sign in with `/login` the way you would on any machine, or set your key in that shell with `export ANTHROPIC_API_KEY=…`.

## 5. Keep it running, or pause it

A new sandbox stops itself after one hour as a safety net. For a long task, extend it or turn auto-stop off:

```bash
sbx extend sb_k3v9x2mq --hours 12
sbx extend sb_k3v9x2mq --no-auto-stop
```

When you're done for the day, stop it. Stopping saves the VM's memory as well as its disk, and a stopped sandbox costs nothing:

```bash
sbx stop sb_k3v9x2mq
sbx resume sb_k3v9x2mq     # tmux, the dev server and the claude session are still running
```

## 6. See what it built

If Claude Code starts a dev server, put the port on an HTTPS URL. It's private with a token by default, or public with `--public`:

```bash
sbx host sb_k3v9x2mq 3000
```

## Run several at once

Each sandbox is its own VM, so you can give every task its own copy. Set one up the way you like, save it as a named snapshot, and start new VMs from it:

```bash
sbx snapshot sb_k3v9x2mq my-repo-ready
sbx new --from my-repo-ready
```

## FAQ

### Can I run Claude Code on a virtual machine?

Yes. Claude Code runs on Linux, and a Sandboxer sandbox is a full Ubuntu 24.04 VM with Claude Code already installed, so there's nothing to set up beyond signing in.

### Is it safe to let Claude Code run without permission prompts in the VM?

It's much safer than on your own computer, because the agent can only touch what's inside that VM. Start it with `--no-env` and only the keys the task needs, so a mistake can't reach your other secrets. See [Claude Code without permission prompts](/guides/claude-code-skip-permissions-safely).

### Does the VM keep working when my laptop is closed?

Yes. The agent runs in the cloud VM, not on your laptop. Use `sbx prompt` or a `tmux` session over SSH, and check back later with `sbx events` or `sbx ssh`.

### What does it cost?

The `default` size (4 vCPU, 8 GB) is $0.036 an hour, billed per second while it runs. A stopped sandbox costs nothing. Your Anthropic usage is billed by Anthropic on your own key.

### Can I use my Claude Pro or Max subscription instead of an API key?

For `sbx prompt` and the API, not yet: the integrated agent uses an API key you add on the **Agents** page, and subscription sign-in is coming. In your own SSH session, Claude Code's `/login` works as it does on any machine.
