{"slug": "a-sandbox-for-claude-code-running-it-headless-in-a-cloud-workspace", "title": "A sandbox for Claude Code: running it headless in a cloud workspace", "summary": "A developer documented a method for running Claude Code headless inside a Sandscale cloud workspace, a Firecracker microVM with its own kernel and persistent disk, so agent commands execute off the local machine. The setup drives Claude Code non-interactively with `claude -p`, pre-approves tools via `--allowedTools`, captures JSON output with a resumable `session_id`, and keeps long runs alive in tmux while the workspace is governed by idle and stop schedules. The writeup warns that without `--bare`, a `-p` session auto-runs project hooks and connects `.mcp.json` servers with no trust prompt, so it should only be pointed at trusted repositories.", "body_md": "**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.\n\nThis 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.\n\nThere are three ways to give Claude Code a separate place to run code, and they solve different problems:\n\nInstall the [CLI](https://sandscale.dev/cli) on macOS or Linux, sign in, then pick a template your organization set up:\n\n```\ncurl -fsSL https://sandscale.dev/install | sh\nsandscale login\nsandscale workspace templates list\nsandscale workspace create claude-box --template TEMPLATE\nsandscale workspace open claude-box\n```\n\n`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.\n\nInside 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.\n\nIf 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.\n\n`-p` (or `--print`) runs Claude Code non-interactively. `--allowedTools` pre-approves the tools the run may use without a prompt:\n\n```\ncd ~/src/my-service\nclaude -p \"Run the test suite, fix the first failing test, and summarize the change\" \\\n  --allowedTools \"Read,Edit,Bash\" \\\n  --output-format json > result.json\n```\n\nPer 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:\n\n```\nsession_id=$(jq -r '.session_id' result.json)\nclaude -p \"Now run the linter and fix what it reports\" --resume \"$session_id\"\n```\n\nTwo 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.\n\nRun 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:\n\n```\nsandscale workspace schedule idle claude-box 30m\nsandscale workspace schedule stop claude-box 8h\n```\n\nYour 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.\n\nReconnect 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:\n\n```\nsandscale workspace port-forward claude-box 3000\n```\n\nWhen you are done for the day, `sandscale workspace stop claude-box` stops it and keeps the disk.\n\nThe 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.\n\nYes. 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.\n\nPass `-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.\n\nYes. 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.\n\nYes, 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.\n\n*Originally published on the [Sandscale blog](https://sandscale.dev/blog/claude-code-headless-in-a-cloud-workspace).*", "url": "https://wpnews.pro/news/a-sandbox-for-claude-code-running-it-headless-in-a-cloud-workspace", "canonical_source": "https://dev.to/sandscale/a-sandbox-for-claude-code-running-it-headless-in-a-cloud-workspace-fm8", "published_at": "2026-11-27 17:31:47+00:00", "updated_at": "2026-11-27 17:44:22.059965+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "ai-infrastructure"], "entities": ["Claude Code", "Anthropic", "Sandscale", "Firecracker", "tmux"], "also_reported_by": [], "takeaway": "Running `claude -p` inside a persistent Firecracker microVM with `--allowedTools` and `--output-format json` lets you resume sessions via `session_id` while keeping agent execution off your laptop, but without `--bare` it auto-runs project hooks and MCP servers with no trust prompt.", "recommendation": {"advice": "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.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/a-sandbox-for-claude-code-running-it-headless-in-a-cloud-workspace", "markdown": "https://wpnews.pro/news/a-sandbox-for-claude-code-running-it-headless-in-a-cloud-workspace.md", "text": "https://wpnews.pro/news/a-sandbox-for-claude-code-running-it-headless-in-a-cloud-workspace.txt", "jsonld": "https://wpnews.pro/news/a-sandbox-for-claude-code-running-it-headless-in-a-cloud-workspace.jsonld"}}