Guide · kosa8 Cloud
How do I run Claude Code in a kosa8 Cloud sandbox?
Updated
Create a sandbox on kosa8 Cloud from the node template, install Claude Code under /workspace (the part of the disk that persists between commands), clone the repository there, and run claude -p through the API's streaming exec so a long task is not cut off. Read the diff, then put the sandbox to sleep so it costs only snapshot storage. Nothing runs on your machine but curl and jq. To keep Claude Code local and only send its commands to the cloud, connect it to kosa8 Cloud's MCP server instead.
01Steps
Make a kosa8 Cloud account and an API key. Sign up at app.kosa8.com, add a payment method (a new organization runs nothing until one is on file), and create an API key. Use an Anthropic key you can revoke, with a spending limit, because unlike a local kosa8 agent run the key is passed into the sandbox.
Add a small helper for streamed commands. Every command in this guide goes through the API's exec route with
"stream": true, which returns output as it is printed and is not held to the 90-second limit of a plain exec. Paste this function into a bash or zsh shell; it prints stdout and stderr as they arrive and the exit code at the end.k8x() { # k8x 'shell line' [NAME=value ...]: run it in $SBX and stream the output body=$(jq -n --arg c "$1" '{cmd: ["sh", "-c", $c], env: $ARGS.positional, stream: true}' --args "${@:2}") curl -sN -X POST "https://api.kosa8.com/v1/sandboxes/$SBX/exec" \ -H "Authorization: Bearer $KOSA8_API_KEY" -H 'Content-Type: application/json' -d "$body" | jq -rj 'if .stream then (.data | @base64d) elif .done then "\n[exit \(.exit)]\n" else empty end' }
Create the sandbox. The
nodetemplate is Node.js 22 on Alpine.sleep_after_sputs it to sleep after 15 idle minutes.SBX=$(curl -s -X POST https://api.kosa8.com/v1/sandboxes \ -H "Authorization: Bearer $KOSA8_API_KEY" -H 'Content-Type: application/json' \ -d '{"template":"node","sleep_after_s":900}' | jq -r .sandbox.id) echo "$SBX"
Install Claude Code under /workspace. Each exec runs in a fresh container on the sandbox's disk: files under
/workspacepersist between commands, packages installed elsewhere do not. So install Claude Code into/workspace/.cc, pinned to a version.Clone the repository. Alpine has no git, and a package added with
apklasts only for that command, so add it in the same line.Run Claude Code headless. Claude Code's Bash tool needs bash, which Alpine lacks, so add it in the same command.
--permission-mode bypassPermissionsturns off Claude Code's prompts, since no one is there to answer them; the sandbox is the boundary.IS_SANDBOX=1lets it run as root. The key goes in the exec's environment, not its arguments.k8x 'apk add --no-cache bash git >/dev/null && cd /workspace/repo && /workspace/.cc/node_modules/.bin/claude -p "Find and fix one failing test, then explain the fix" \ --permission-mode bypassPermissions' \ "ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY" IS_SANDBOX=1
Read what it changed. The repository and Claude Code's changes are on the sandbox's disk.
Put it to sleep, or delete it. A sleeping sandbox costs only snapshot storage, and the next exec wakes it with
/workspaceintact, so the next task skips the install. Delete it when you are done; its disk is wiped.curl -s -X POST "https://api.kosa8.com/v1/sandboxes/$SBX/sleep" -H "Authorization: Bearer $KOSA8_API_KEY" curl -s -X DELETE "https://api.kosa8.com/v1/sandboxes/$SBX" -H "Authorization: Bearer $KOSA8_API_KEY"
02Or keep Claude Code local and give it cloud sandboxes
If you want Claude Code's interface on your machine but its commands somewhere else, connect it to kosa8 Cloud's remote MCP server. It can then create cloud sandboxes, run commands in them, put them to sleep and delete them.
The difference matters: in this mode Claude Code itself, and its own file tools, still run on your machine; only the commands it sends to sandbox_exec run in the cloud, each for at most 30 seconds. Give the agent its own API key with the sandboxes:write scope so you can revoke it alone.
03What is different from running it locally
- The API key is inside. Locally,
kosa8 agent run claudekeeps the key on your machine and the sandbox holds a placeholder. In this cloud recipe the key is in the exec's environment, so Claude Code can read it. Use a dedicated key with a spending limit. - The network is open. A cloud sandbox can reach the internet; kosa8 Cloud has no org-wide egress policy setting yet. Locally, the claude kit allows only the hosts it needs.
- Background processes end with each command. Only
/workspacecarries over, which is why the install goes there and system packages are added per command. - It keeps running when your laptop sleeps. That is the point: start a long task, close the lid, read the diff later.
04Why run Claude Code in the cloud at all?
Because the machine Claude Code runs on is the machine it can damage. In a cloud sandbox it has no access to your home directory, your SSH keys or your other projects, and a task can run for an hour without your laptop being awake. kosa8 Cloud's audit log records each exec's arguments and the names, not the values, of its environment variables.
05FAQ
Does kosa8 Cloud have a built-in Claude Code kit?
The kits (kosa8 agent run claude) run on your own machine, with the key brokered. On kosa8 Cloud you install Claude Code into /workspace as in this guide, or connect a local Claude Code to the cloud MCP server.
Why does the command need stream: true?
An exec answered as one JSON object runs at most 90 seconds, then returns 504 exec_timeout. With "stream": true the output arrives as NDJSON while the command runs, and the command is not held to that limit.
What does a sandbox like this cost?
A kosa8 plan includes Cloud sandbox-hours, counted by vCPU while a sandbox runs; a sleeping sandbox uses none, and pays only for its snapshot storage. Current rates are on the pricing page.
Can I use a Claude subscription instead of an API key?
This recipe passes ANTHROPIC_API_KEY. Claude Code also reads CLAUDE_CODE_OAUTH_TOKEN from claude setup-token; pass it the same way, and treat it with the same care.
06Get started
Install kosa8 on a Mac, Linux or Windows (WSL2) machine, or make an account and run the same sandboxes on kosa8 Cloud.
07Sources
- kosa8 docs: kosa8 Cloud
- kosa8 docs: kosa8 Cloud MCP server
- kosa8 docs: kosa8 Cloud security
- Claude Code docs: headless mode
- kosa8 command reference
Related
- How do I run Claude Code safely on a Mac?
- How do I run Claude Code safely on Linux?
- The best sandbox for the Claude Agent SDK
- The best sandbox for CI/CD pipelines that run AI-generated code
- How do I give an AI agent API keys without exposing them?
Updated 2026-11-14