Run Claude Code and Codex in a cloud sandbox
Give Claude Code, Codex or OpenCode a task and a sandbox where it may install, run and change anything without asking, holding none of your API keys. One call sends the prompt; another streams each file it reads, each edit and each command it runs.
- A microVM per sandbox
- Starts in 0.15 s
- $0.018/h, billed per second
How to run Claude Code in a sandbox
Keep your API key as a secret
Save it once in the workspace with the hosts it may go to. The agent’s variable holds a placeholder, and the real key is added to its requests to those hosts, outside the sandbox.
Make a sandbox and prompt the agent
All three agents are installed in every sandbox.
prompt_agentstarts a turn in a new conversation or one you name, with the model and the directory you pick.Watch it work, then go on
watch_conversationstreams each message, tool call and result as it happens. Send the next prompt to the same conversation, and the agent goes on with what it knows.
import os
from pethost.sandboxes import (EnvVar, Environment, Sandboxes,
SandboxSettings)
sandboxes = Sandboxes() # reads PETHOST_TOKEN
key = os.environ["ANTHROPIC_API_KEY"]
sandboxes.set_secret("anthropic", value=key,
hosts=["api.anthropic.com"])
env = Environment(variables=[
EnvVar(name="ANTHROPIC_API_KEY", secret="anthropic")])
box = sandboxes.create_sandbox(
settings=SandboxSettings(environment=env))
prompt = "Write fizzbuzz.py with a test and run it"
turn = sandboxes.prompt_agent(box.sandbox_id, prompt=prompt,
wait_seconds=0)
conversation = turn.conversation_id
for event in sandboxes.watch_conversation(
box.sandbox_id, conversation_id=conversation):
if event.tool_call:
print("›", event.tool_call.name, event.tool_call.input[:60])
elif event.turn_end:
print(event.turn_end.state.name, event.turn_end.reply)
breakpethost sandbox secret set anthropic --host api.anthropic.com < key.txt
pethost sandbox new --name fizzbuzz --env ANTHROPIC_API_KEY=secret:anthropic
pethost sandbox agent fizzbuzz "Write fizzbuzz.py with a test and run it"
pethost sandbox agent fizzbuzz --agent opencode "Explain fizzbuzz.py"Why run coding agents in a Pethost sandbox
Three agents, installed
Claude Code, Codex and OpenCode come with their CLIs on the PATH, beside git, Python 3, Node.js 22 and Docker. A sandbox starts in about 0.15 s.
Full autonomy, no approvals
Claude Code runs in
bypassPermissionsmode, Codex with full access, OpenCode with every tool allowed. The sandbox, a Firecracker microVM, is the boundary.Your key stays outside
The agent and every process see a placeholder, and the real key is added only to their requests to the hosts you name, such as
api.anthropic.com.One stream for all three
watch_conversationgives each prompt, message, tool call with its input as JSON, result and turn’s end, in the same shape for every agent.Paused while you review
Idle for 5 minutes between turns, the sandbox pauses with its files, processes and conversations at 30% of the price. The next prompt wakes it in about 0.1 s.
Its dev server stays up
When a turn ends, what the agent started in the background runs on: open the dev server it started at its preview URL, or SSH in and look.
What teams use it for
Background coding agents
Your product takes an issue, starts a sandbox with the repository, has Claude Code fix it and run the tests, then reads the result back.
Long tasks off your laptop
Give an agent a task that takes an hour in a sandbox, and look in from the web console’s Agents tab or a terminal while it works.
Comparing agents and models
Give one task to Claude Code, Codex and OpenCode, each in a sandbox from the same template, and compare their results and the tokens each turn used.
Signing in without the key inside
Bind ANTHROPIC_API_KEY or OPENAI_API_KEY to a workspace secret, and the key never enters the sandbox. How secrets the sandbox never holds work.
Or a person signs in once in the sandbox’s terminal, with claude auth login or codex login --device-auth, and the login stays on its disk, as on your computer. OpenCode needs no sign-in at all: without a provider’s key it uses OpenCode’s own free models. A prompt to an agent that cannot reach its model is refused with the variable to set and the command that signs in.
Limits and prices
A conversation runs one turn at a time, and further prompts wait in line. A call waits up to 45 seconds for a turn and answers its state, the agent’s last message up to 16 KiB and the tokens it used; a longer turn goes on.
The agent runs on the sandbox’s vCPUs and memory, billed by the second at its size’s price, $0.018 an hour for SMALL (2 vCPU, 4 GiB) and $0.036 for DEFAULT (4 vCPU, 8 GiB). A running turn keeps the sandbox awake; between turns, idle for 5 minutes, it pauses at 30% of that price. The model’s tokens are your provider’s bill, not ours.
How it compares
On 21 November 2026, boat.dev’s proxy that keeps AI keys out of its sandboxes cost $1 for each day it is on, plus $1 per 1,000 requests. At Pethost the swap is part of every sandbox, for any key and any HTTPS host you name, with no price of its own.
Every sandbox, in numbers
Pethost Agent Sandboxes are cloud VMs for AI agents. Each is a Firecracker microVM with its own kernel and root inside: it starts in about 0.15 s, pauses with its memory while the agent thinks, and wakes at the next call. Billed by the second, in the EU.
- ~0.15 s to start a sandbox from a template
- ~0.1 s to wake a paused one, memory and processes as they were
- $0.018/h for 2 vCPU, 4 GiB and 10 GiB while running
- 1 s billing step: each run rounded up to a second, 10 s at least
- $0 to create or start a sandbox
Measured on our servers on 18 November 2026, through an API 16 ms away: a create’s median 123 ms (SMALL) to 158 ms (XLARGE), a resume 124 ms, a command to a paused sandbox 80 ms.
Questions
Do I need an API key to run Claude Code in a sandbox?
For Claude Code and Codex, either a key bound as a secret or a person’s sign-in in the terminal. Claude Code also signs in with CLAUDE_CODE_OAUTH_TOKEN, Bedrock or Vertex. OpenCode runs with no key, on its own free models.
Does my key enter the sandbox?
Not when it is a secret: the agent and every process see a placeholder, and the key is added to its requests outside the sandbox. A sign-in made in the terminal is stored inside the sandbox, as on your computer.
Does the agent ask before running commands?
No. Every permission is granted, because the sandbox is a microVM with nothing of yours inside but what you put there. Narrow its egress for untrusted work.
Can I watch the agent work?
Yes: stream its conversation with watch_conversation, or open its Agents tab in the web console. A terminal link that runs claude gives you a session of your own beside it.
Does a conversation survive a pause?
Yes: it stays with the sandbox’s files, and the next prompt picks it up. A template keeps no conversations, so a sandbox started from one begins with none.
Everything else a sandbox does
- Save a sandbox as a templateSet a sandbox up once and save it as a template, packages and Docker images included; start as many sandboxes as you need from it, each in about 0.22 s.
- API keys the sandbox never holdsCode in the sandbox sees a placeholder. Its requests still work: the real API key is put in on the way out, only to the hosts you name.
- A microVM with its own kernelEach sandbox is a Firecracker microVM with its own Linux kernel and root inside: install anything, run Docker, change any file. It starts in about 0.15 s.
- Pauses with its memoryA paused sandbox keeps its memory, processes and files at 30% of the price, and the next call wakes it in about 0.1 s, exactly where it was.
- Pauses itself when idleFive minutes without a call and a sandbox pauses, memory kept; thirty and it stops, files kept. Every timer is set per sandbox, and 0 turns it off.
- Billed by the second, starts freeRunning time by the second from $0.018 an hour, paused time at 30% of that, a stopped sandbox by the GiB of its own files. Creating and starting one cost nothing.
- Code execution in one callRun the code your model writes and get its exit code and output in one call, stream long jobs, edit files by exact replacement, and open a terminal in the browser.
- A desktop with ChromeEvery sandbox has a 1280×800 screen with Chrome: click, type and screenshot in one call, drive it with Playwright or Puppeteer, or watch it live and take over.
- Plain SSH, scp and tunnelsssh, scp, sftp and ssh -L into any sandbox with a workspace key or a token as the password; a login wakes a paused one.
- A URL for every portA dev server on port 3000 answers at its own HTTPS address, public or behind a token, and a visit wakes a paused sandbox in about 0.2 s.
- Only the hosts you allowList the domains, IPs and ports a sandbox may reach: every other host is refused, even in DNS, and a change applies while it runs.
- See everything a sandbox didCPU, memory, disk and network for 24 hours, and every change of state, command, host reached and agent turn, as a list or a live stream.
Give your agent a computer in 0.15 s
From $0.018 an hour for 2 vCPU and 4 GiB, billed by the second. Paused, 30% of that. Starting one is free.