English
Get started
Pethost Agent Sandboxes

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

  1. 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.

  2. Make a sandbox and prompt the agent

    All three agents are installed in every sandbox. prompt_agent starts a turn in a new conversation or one you name, with the model and the directory you pick.

  3. Watch it work, then go on

    watch_conversation streams 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)
        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"

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 bypassPermissions mode, 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_conversation gives 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.

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

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.

Start the free trial