# A sandbox for Claude Code: running it headless in a cloud workspace

> Run Claude Code with claude -p inside a Sandscale workspace, a persistent Firecracker microVM, so its Bash tool works on a cloud disk instead of your laptop. Setup, permission flags and what stays where.

Run Claude Code with claude -p inside a Sandscale workspace, a persistent Firecracker microVM, so its Bash tool works on a cloud disk instead of your laptop. Setup, permission flags and what stays where.

November 27, 2026 · 6 min read · The Sandscale team

**Short answer:** if you want Claude Code’s commands off your machine, run Claude Code itself on a cloud computer and drive it with `claude -p`. A Sandscale [workspace](https://sandscale.dev/workspaces) is a Firecracker microVM with its own kernel and a disk that survives between sessions, so the repository, the installed tools and Claude Code’s own session files are still there next time, and nothing it runs touches your laptop.

This guide uses Sandscale’s [workspaces guide](https://sandscale.dev/docs/guides/workspaces) and [workspace reference](https://sandscale.dev/docs/reference/cli/workspace) for the Sandscale side, and Anthropic’s [Run Claude Code programmatically](https://code.claude.com/docs/en/headless) page for the Claude Code side, read in November 2026.

## Workspace, sandbox or MCP?

There are three ways to give Claude Code a separate place to run code, and they solve different problems:

- **Claude Code runs locally, commands run in a sandbox.** Connect the [Sandscale MCP server](https://sandscale.dev/blog/sandscale-mcp-server-in-claude-code) and let Claude Code start sandboxes and run commands in them. Your files stay local; only what the agent sends goes to the sandbox.
- **Claude Code runs in a workspace.** Everything, including the agent’s edits, happens on the workspace. This is the setup in this post, and it suits long tasks that should keep going when your laptop is closed.
- **Agent Cloud.** Sandscale hands the task to an agent in one of your workspaces and returns a branch and pull request. See [Agent Cloud](https://sandscale.dev/docs/concepts/agent-cloud).

## 1. Create and open a workspace

Install the [CLI](https://sandscale.dev/cli) on macOS or Linux, sign in, then pick a template your organization set up:

```sh
curl -fsSL https://sandscale.dev/install | sh
sandscale login
sandscale workspace templates list
sandscale workspace create claude-box --template TEMPLATE
sandscale workspace open claude-box
```

`TEMPLATE` is one of the names `templates list` prints. `open` starts the workspace if it is stopped, waits until it runs, and connects over SSH with a short-lived certificate and a checked host key. Claude Code needs to reach Anthropic’s API, so the workspace needs network access; network follows your plan and your organization’s policy, so check that yours lets the workspace reach that API.

## 2. Install and sign in to Claude Code on the workspace

Inside the workspace shell, install Claude Code the way Anthropic’s setup docs describe, clone your repository, and sign in once. Because the workspace disk persists, the sign-in and the clone are still there after the workspace stops and starts again.

If you run Claude Code with `--bare`, it does not read OAuth credentials or the keychain, and Anthropic’s docs say to set `ANTHROPIC_API_KEY` in the environment instead. Export it in the shell session rather than writing it into a file inside the repository.

## 3. Run it headless

`-p` (or `--print`) runs Claude Code non-interactively. `--allowedTools` pre-approves the tools the run may use without a prompt:

```sh
cd ~/src/my-service
claude -p "Run the test suite, fix the first failing test, and summarize the change" \
  --allowedTools "Read,Edit,Bash" \
  --output-format json > result.json
```

Per Anthropic’s docs, Claude Code exits 0 on success and non-zero when the run fails, and with `--output-format json` the text is in the `result` field and the session ID in `session_id`. To continue the same session later:

```sh
session_id=$(jq -r '.session_id' result.json)
claude -p "Now run the linter and fix what it reports" --resume "$session_id"
```

Two notes from the same page. Without `--bare`, a `-p` session runs the hooks in a project’s `.claude/settings.json` and connects the servers in its `.mcp.json` with no trust prompt, so only point it at repositories you would open yourself. With `--bare`, it skips that auto-discovery but still reads settings files and their permission rules.

## 4. Keep it running after you disconnect

Run the command inside a terminal multiplexer such as `tmux` on the workspace, detach, and close your laptop. The workspace keeps running until it is stopped, goes idle, or hits a stop schedule:

```sh
sandscale workspace schedule idle claude-box 30m
sandscale workspace schedule stop claude-box 8h
```

Your organization’s policy can shorten what you set, and `sandscale workspace schedule show claude-box` prints the values in force. Hours count against your plan only while the workspace runs.

## 5. Look at the result from your machine

Reconnect with `sandscale workspace open claude-box`, or with `sandscale workspace ssh` from an editor that connects over SSH. If the agent started a dev server, reach it locally without opening anything to the internet:

```sh
sandscale workspace port-forward claude-box 3000
```

When you are done for the day, `sandscale workspace stop claude-box` stops it and keeps the disk.

## What Sandscale adds around it

The workspace is a separate microVM, so a bad command hits the workspace’s disk, not yours. Starting, stopping and connecting are in your organization’s audit log, policies decide which templates and sizes members may use, and secrets can come from [Vault](https://sandscale.dev/docs/concepts/vault) instead of a prompt. Claude Code’s own permission rules still decide which tools the model may call; the workspace decides where those calls land.

## FAQ

### Can I sandbox Claude Code without Docker?

Yes. Running Claude Code inside a Sandscale workspace puts it in a Firecracker microVM with its own kernel, so its Bash tool runs there instead of on your machine. You do not need Docker on your laptop for this.

### How do I run Claude Code non-interactively?

Pass `-p` with a prompt, for example `claude -p "fix the failing test" --allowedTools "Read,Edit,Bash"`. Add `--output-format json` to get the result and session ID as JSON, and `--resume` with that session ID to continue.

### Does the workspace keep Claude Code’s session when it stops?

Yes. A workspace keeps its disk when it stops, so the repository, installed tools and Claude Code’s session files are still there when you open it again. Deleting the workspace deletes its disks.

### Does the workspace need network access?

Yes, Claude Code calls Anthropic’s API. Network access follows your plan and your organization’s policy, so check that yours lets the workspace reach that API.

## Related

- [Setting up the Sandscale MCP server in Claude Code](https://sandscale.dev/blog/sandscale-mcp-server-in-claude-code)
- [Use case: a coding agent that keeps working after you close the laptop](https://sandscale.dev/blog/use-case-long-running-agent-in-a-workspace)
- [Running Codex with codex exec in a cloud workspace](https://sandscale.dev/blog/codex-exec-in-a-cloud-workspace)
- [Running Gemini CLI headless in a cloud workspace](https://sandscale.dev/blog/gemini-cli-headless-in-a-cloud-workspace)

**On this page**

1. Workspace, sandbox or MCP?
2. 1. Create and open a workspace
3. 2. Install and sign in to Claude Code on the workspace
4. 3. Run it headless
5. 4. Keep it running after you disconnect
6. 5. Look at the result from your machine
7. What Sandscale adds around it
8. FAQ
9. Related

**Run your agents in a box of their own**

Each sandbox is a Firecracker microVM. Free includes 100 awake vCPU-hours a month.

[Start free](https://cloud.sandscale.dev/auth/signup)

## Keep reading

- [November 27, 2026 · **A LlamaIndex.TS data agent that runs its Python in a Sandscale sandbox** · Use LlamaIndex.TS's agent workflow with tools that write and run Python in a Firecracker sandbox, built per sandbox so a run can only reach its own box. Upload data files, answer with the numbers, clean up. Type-checked.](https://sandscale.dev/blog/llamaindex-ts-agent-with-sandscale)
- [November 27, 2026 · **A sandbox for Codex: running codex exec in a cloud workspace** · Run OpenAI Codex non-interactively with codex exec inside a Sandscale workspace, a persistent Firecracker microVM, and drive it from your laptop over SSH. Sandbox modes, JSON output and schedules.](https://sandscale.dev/blog/codex-exec-in-a-cloud-workspace)

---
Source: https://sandscale.dev/blog/claude-code-headless-in-a-cloud-workspace
