# How do I run Claude Code on a cloud computer that keeps its files?

> Install Claude Code on a cloud machine whose disk outlives each session. A Sanbox Computer keeps your repository, installed packages and Claude Code settings across stop and resume.

- Source: Sanbox knowledge base, by Sanlabs GmbH
- URL: https://sanbox.cloud/kb/coding-agents/claude-code-on-a-cloud-computer-that-keeps-files/
- Type: how-to
- Section: Coding agents in the cloud
- Language: en
- Published: 2026-11-06
- Updated: 2026-11-06

Run Claude Code on a machine whose disk outlives each session, and keep your work on that disk. Anthropic's cloud sessions keep the conversation, but their VM is reclaimed after a period of inactivity, so unpushed work can be lost; a VPS keeps files, but you maintain it. On Sanbox, an OpenCode Computer has its own private disk that stop and resume keep: your repository in `/workspace`, the packages you install, including Claude Code, and Claude Code's settings and history in your home directory.

## Run this with your agent

```text
Read https://sanbox.cloud/kb/coding-agents/claude-code-on-a-cloud-computer-that-keeps-files.md and follow it to set up Claude Code on a Computer that keeps its files.
If the Sanbox CLI is missing, install it with `npm install -g @sanlabs/sanbox-cli@latest`
and sign in with `sanbox login`. Show me each command before you create, stop or delete a Computer.
```

## What does a Computer keep?

Stop ends compute and saves the disk. Computers from current OpenCode templates are writable, so the saved disk holds `/workspace` and persistent system changes such as installed packages. Resume boots a fresh system on that same disk.

| What | Stop, then resume | Fork | Snapshot | Delete |
|---|---|---|---|---|
| Your repository in `/workspace` | Kept | Copied | Copied | Removed |
| Claude Code installed with npm | Kept | Copied | Copied | Removed |
| Claude Code settings, history and login (`~/.claude`, `~/.claude.json`) | Kept | Copied | Copied | Removed |
| The running `claude` process and RAM | Ended | Not copied | Not copied | Removed |
| Commands started with `sanbox exec` | Forgotten | Not copied | Not copied | Removed |

Forks and snapshots copy files as they are, including any login stored in them.

## Steps

### 1. Create a template with room for your code

Save the hosts Claude Code needs as `claude-code-policy.json`:

```json
{
  "default_action": "deny",
  "rules": [
    { "destination": "registry.npmjs.org", "ports": [{ "from": 443, "to": 443 }] },
    { "destination": "api.anthropic.com", "ports": [{ "from": 443, "to": 443 }] },
    { "destination": "claude.ai", "ports": [{ "from": 443, "to": 443 }] },
    { "destination": "platform.claude.com", "ports": [{ "from": 443, "to": 443 }] },
    { "destination": "github.com", "ports": [{ "from": 443, "to": 443 }] }
  ]
}
```

Then create the template and give its Computers the largest disk, 8 GB (the default is 4 GB). The disk holds `/workspace` and every installed package:

```bash
sanbox templates create --name "Claude Code" --type opencode-computer \
  --model-provider <provider-id> --model <model-id> \
  --network-policy claude-code-policy.json --json
sanbox templates storage set <template-id> --gb 8 --json
sanbox templates validate <template-id> --json
```

The template's own OpenCode agent uses the provider and model you pick; `sanbox model-providers list --json` shows them. Claude Code uses its own sign-in.

### 2. Start the Computer and install Claude Code

```bash
sanbox run --template <template-id> --external-run-id claude-code-repo --json
sanbox runs get <run-id> --json
sanbox exec <run-id> --root -- npm install -g @anthropic-ai/claude-code
sanbox exec <run-id> -- claude --version
```

Wait for the state `running` before you install. Claude Code's npm package needs Node 22 or later, which the image has. Its docs advise against root installs because Claude Code then can't update itself, so update it by rerunning the install with `@anthropic-ai/claude-code@latest`.

### 3. Put your code in /workspace

Copy a local checkout in, or clone it inside the Computer:

```bash
sanbox cp ./<repo> <run-id>:/workspace
sanbox exec <run-id> --cwd /workspace -- git clone https://github.com/<owner>/<repo>.git
```

`sanbox cp` lands the folder under its own name, so `./<repo>` becomes `/workspace/<repo>`. Uploads must finish in about five minutes, so clone large repositories instead.

### 4. Sign in and work

Open a terminal on the Computer: the console's browser terminal, or `sanbox ssh <run-id>` from yours. Then:

```bash
cd /workspace/<repo>
claude
```

Claude Code prints a sign-in URL. Open it on any device, sign in, and paste the code back. The console terminal and SSH can use different home directories, so keep using the one you signed in from. The console terminal keeps running when you close the tab; over SSH, run `zellij attach --create claude` first for the same effect.

### 5. Stop, resume and check what stayed

```bash
sanbox runs stop <run-id> --wait --json
sanbox runs resume <run-id> --wait --json
sanbox exec <run-id> -- claude --version
sanbox exec <run-id> --cwd /workspace/<repo> -- git status
```

Open a terminal, `cd` into the repository and run `claude --continue` to pick up the last conversation.

### 6. Copy results out

Push from inside the Computer, or copy files back to your machine while it runs:

```bash
sanbox cp <run-id>:/workspace/<repo>/dist ./dist
```

## Snapshot it

A snapshot is a named copy of a stopped Computer, and every run started from it begins with the same disk. Take it before you sign in, so the copy holds Claude Code and the repository but no login:

```bash
sanbox runs stop <run-id> --wait --json
sanbox snapshots create --run <run-id> --name claude-code-base --wait
sanbox run --snapshot claude-code-base --json
```

For a team, a template built from the snapshot starts every Computer as a copy of it, and `sanbox templates update <template-id> --snapshot <other-snapshot>` moves the template to a newer one:

```bash
sanbox templates create --name "Claude Code base" --snapshot claude-code-base --json
```

## Lock down egress

The policy above allows only the install, the model API, the sign-in and GitHub. Add other registries your project installs from, such as `pypi.org` or `deb.debian.org`, as their own rules. A blocked request names the host it couldn't reach.

## What this doesn't do

- It doesn't keep running processes. A stop ends Claude Code mid-task; you resume the conversation, not the process.
- Disks go up to 8 GB per Computer. Larger disks are available on request from sales@sanlabs.ai.
- Delete is permanent. It removes the saved disk, including anything you didn't push or copy out.
- Your login is a file on the disk, and people in your organisation who can open the run's terminal can use it. Plan logins are personal: on a Computer several people share, use an API key.
- To keep it running around the clock and reach it from a phone, see the [24/7 guide](https://sanbox.cloud/kb/coding-agents/claude-code-24-7-from-your-phone/).

## Related

- [How do I keep Claude Code running 24/7 and control it from my phone?](https://sanbox.cloud/kb/coding-agents/claude-code-24-7-from-your-phone/)
- [What survives when an agent's computer stops?](https://sanbox.cloud/kb/agent-computers/what-survives-a-stop/)
- [Persistent vs ephemeral sandboxes for AI agents](https://sanbox.cloud/kb/agent-computers/persistent-vs-ephemeral-sandboxes/)
- [How do I log in to Claude Code or Codex on a headless server?](https://sanbox.cloud/kb/coding-agents/log-in-to-claude-code-or-codex-on-a-headless-machine/)
- [Claude Code on the web vs your own cloud computer](https://sanbox.cloud/compare/claude-code-on-the-web-vs-your-own-cloud-computer/)

## Sources

- Claude Code docs, [Advanced setup](https://code.claude.com/docs/en/setup): npm install, Node 22, the advice against `sudo` installs, `~/.claude` and `~/.claude.json`. Checked 2026-11-06.
- Claude Code docs, [Enterprise network configuration](https://code.claude.com/docs/en/network-config): required hosts. Checked 2026-11-06.
- Claude Code docs, [Use Claude Code in the cloud](https://code.claude.com/docs/en/claude-code-on-the-web): cloud sessions stop after inactivity and their VM is reclaimed. Checked 2026-11-06.
- Claude Code docs, [Remote Control](https://code.claude.com/docs/en/remote-control): `claude --continue` resumes a conversation. Checked 2026-11-06.

## Next step

Talk to us at sales@sanlabs.ai. Sanlabs' forward-deployed engineers build agent use cases with your team, with experience in aviation, pharmaceuticals, supply chain and logistics, and internal admin workflows. How we work: https://sanbox.cloud/kb/teams/forward-deployed-engineering.md

Existing customers can use Sanbox from a coding agent: install the CLI with `npm install -g @sanlabs/sanbox-cli@latest`, sign in with `sanbox login`, then run `sanbox skill` for the full agent guide.
