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)
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"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.