Guide
How do I run Claude Code on a cloud computer that keeps its files?
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
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:
{
"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:
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
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:
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:
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
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:
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:
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:
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.
Related
- How do I keep Claude Code running 24/7 and control it from my phone?
- What survives when an agent's computer stops?
- Persistent vs ephemeral sandboxes for AI agents
- How do I log in to Claude Code or Codex on a headless server?
- Claude Code on the web vs your own cloud computer
Sources
- Claude Code docs, Advanced setup: npm install, Node 22, the advice against
sudoinstalls,~/.claudeand~/.claude.json. Checked 2026-11-06. - Claude Code docs, Enterprise network configuration: required hosts. Checked 2026-11-06.
- Claude Code docs, Use Claude Code in the cloud: cloud sessions stop after inactivity and their VM is reclaimed. Checked 2026-11-06.
- Claude Code docs, Remote Control:
claude --continueresumes a conversation. Checked 2026-11-06.