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

> Source: <https://dev.to/sandscale/a-sandbox-for-claude-code-running-it-headless-in-a-cloud-workspace-fm8>
> Published: 2026-11-27 17:31:47+00:00

**Recommendation:** Run headless Claude Code in an isolated cloud workspace and only point `-p` at repositories you trust, since non-bare sessions auto-execute `.claude/settings.json` hooks and `.mcp.json` servers without a trust prompt.
More in the playbook "Securing agents and AI tools": <https://wpnews.pro/playbooks/agent-security>

**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.

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

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

```
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.

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.

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

```
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:

```
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.

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:

```
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.

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:

```
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.

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.

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.

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.

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.

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.

*Originally published on the [Sandscale blog](https://sandscale.dev/blog/claude-code-headless-in-a-cloud-workspace).*
