English
Get started

Agent Sandboxes Coding agents, installed

Coding agents in the cloud: Claude Code, Codex and OpenCode

Run Claude Code, Codex or OpenCode in the cloud at full autonomy, each in a VM made for the task: the agent may do anything inside it, and it holds none of your keys.

Three coding agents, installed

Our base template has Claude Code, Codex and OpenCode installed with their official SDKs, and their CLIs on the PATH: claude, codex, opencode. Each runs without asking for permission: Claude Code in bypassPermissions mode, Codex with full access and no approvals, OpenCode with every permission allowed and its question tool off, since nobody would answer it. The sandbox is the boundary: a Firecracker microVM with its own kernel, where the agent has root and reaches what your egress allow-list lets it.

One call per prompt

prompt_agent gives an agent a prompt, in a new conversation or one you name, with a model and a working directory if you want them, and waits up to 45 seconds for the turn. A conversation runs one turn at a time: further prompts are queued. A turn answers its state (QUEUED, RUNNING, DONE, FAILED, STOPPED or LOST), the agent’s last message up to 16 KiB, and the tokens it read and wrote. get_agent_turn waits for a longer turn, and stop_agent_turn ends one.

watch_conversation streams what the agent does, in the same shape for all three agents: each prompt, each message it writes, each tool call with its input as JSON, each result, and the end of each turn. When a turn ends, the agent ends with it, but what it started in the background runs on: a dev server it started is still there to open at its preview URL.

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)
        break
pethost 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"

Signing in without the key inside

Keep your API key as a workspace secret and bind it to ANTHROPIC_API_KEY or OPENAI_API_KEY. The variable inside the sandbox holds a placeholder, and the egress proxy outside the VM puts the real key into the request headers, only on the way to the hosts the secret names, such as api.anthropic.com. A program that prints its environment sees the placeholder. 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. 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, so your code can say what is missing.

The conversation stays with the sandbox

A conversation’s history is on the sandbox’s disk. A pause keeps it with the agent’s files and processes, and the next prompt picks it up. A fork carries it: copy a sandbox between two turns into ten, and send each copy’s conversation its next prompt in another direction. A template keeps no conversations: a sandbox started from one begins with none.

To watch an agent work, stream its conversation, or open the sandbox’s page in the web console, whose Agents tab shows its conversations.

Limits and prices

One turn at a time per conversation. 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.

Read the docs

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 requests outside the VM. A sign-in made in the terminal is stored inside the sandbox, as on your computer.

Can I branch a conversation?

Yes: fork the sandbox. Each copy carries the conversation, and a prompt with its id goes on from there in that copy alone.

Can I watch the agent work?

Yes: stream its conversation with watch_conversation, or open the sandbox in the web console. A terminal link that runs claude gives you a session of your own beside it.

Related

Give your agent a computer in 0.15 s

Start the free trial