English
Docs menu

Agent Sandboxes docs · Tasks

Claude and OpenAI computer use on a sandbox

Updated · 9 min read

Claude and OpenAI's models have computer tools of their own: they answer with clicks, keys, page actions or code, and your program carries them out somewhere. pethost-toolsets carries them out in a sandbox, on its 1280×800 desktop or in its Chrome, so the model gets a whole computer that pauses when the work stops.

In short
  • Claude: ClaudeComputer for its computer toolset and ClaudeBrowser for its browser toolset.
  • OpenAI: OpenAIComputer and OpenAIBrowser, drivers of the openai SDK's ComputerToolset and BrowserToolset, and OpenAICode, its computer use by code: exec_py and exec_js, run in the sandbox.
  • One package, in Python and TypeScript: pethost-toolsets, with the provider's SDK and Playwright as extras. It brings the Pethost SDK with it.
  • One call an action: a computer action is one ControlDesktop, a browser driver drives the sandbox's Chrome with Playwright through a browser link, and a run of code is one RunCommand.
  • One computer: every driver uses the same desktop and the same Chrome, which a person can watch live and take over.

Step 1: Install

Python 3.11 or later, or Node.js 22 or later. Each driver needs its model provider's SDK beside it, and a browser driver Playwright: in Python they are the extras claude, openai and browser, in TypeScript the packages beside it. You need a Pethost API token in PETHOST_TOKEN (the quickstart makes one) and the provider's key.

pip install 'pethost-toolsets[claude,openai,browser]'

npm install pethost-toolsets @anthropic-ai/sdk openai playwright-core

Playwright only connects to the sandbox's Chrome, so it downloads no browser.

Step 2: Give Claude the desktop

The computer toolset sees the screen and acts on it: every action is one ControlDesktop, and the screenshot is the whole screen, unscaled, so Claude's coordinates are the screen's pixels. confirm is the Anthropic SDK's, asked before each action: here it allows everything, for a sandbox that holds nothing of yours.

Python
from anthropic import Anthropic
from pethost.sandboxes import Sandboxes
from pethost_toolsets import ClaudeComputer

with Sandboxes() as sandboxes:  # the token: PETHOST_TOKEN
    sandbox = sandboxes.create_sandbox("base")
    with ClaudeComputer(sandboxes, sandbox.sandbox_id, confirm=lambda context: True) as computer:
        runner = Anthropic().beta.messages.tool_runner(
            model="claude-opus-5-5",
            max_tokens=16000,
            tools=[computer],
            messages=[{"role": "user", "content": "Open Chrome, go to pethost.dev and tell me the page's heading."}],
        )
        for message in runner:
            print(message.content)
TypeScript
import Anthropic from "@anthropic-ai/sdk";
import { Sandboxes } from "pethost/sandboxes";
import { ClaudeComputer } from "pethost-toolsets/claude/computer";

const sandboxes = new Sandboxes({ token: process.env.PETHOST_TOKEN! });
const { sandboxId } = await sandboxes.createSandbox({ template: "base" });

const computer = new ClaudeComputer({ sandboxes, sandboxId, confirm: () => true });
try {
  const runner = new Anthropic().beta.messages.toolRunner({
    model: "claude-opus-5-5",
    max_tokens: 16000,
    tools: [computer],
    messages: [{ role: "user", content: "Open Chrome, go to pethost.dev and tell me the page's heading." }],
  });
  for await (const message of runner) console.log(message.content);
} finally {
  await computer.close();
}

Step 3: Give Claude the browser

The browser toolset reads pages and acts on their elements, in tabs. With sandboxes and the sandbox from the step above, connect makes a browser link, starts the desktop if it does not run (some seconds) and connects Playwright to the sandbox's Chrome. Every tab of that Chrome is reported, those a page or a person opens too.

Python
from pethost_toolsets import ClaudeBrowser

with ClaudeBrowser.connect(sandboxes, sandbox.sandbox_id) as browser:
    runner = Anthropic().beta.messages.tool_runner(
        model="claude-opus-5-5",
        max_tokens=16000,
        tools=[browser],
        messages=[{"role": "user", "content": "Open pethost.dev/sandboxes and say what a sandbox costs."}],
    )
    for message in runner:
        print(message.content)
TypeScript
import { ClaudeBrowser } from "pethost-toolsets/claude/browser";

const browser = await ClaudeBrowser.connect({ sandboxes, sandboxId });
try {
  const runner = new Anthropic().beta.messages.toolRunner({
    model: "claude-opus-5-5",
    max_tokens: 16000,
    tools: [browser],
    messages: [{ role: "user", content: "Open pethost.dev/sandboxes and say what a sandbox costs." }],
  });
  for await (const message of runner) console.log(message.content);
} finally {
  await browser.close(); // disconnects; Chrome and its tabs stay as they are
}

Step 4: Give OpenAI's model the desktop

With the same sandbox, OpenAIComputer is a driver of the openai SDK's ComputerToolset, which runs OpenAI's computer tool: every action of a batch the model sends is one ControlDesktop, and the screenshot after the batch is the whole screen. Key names go to the desktop as OpenAI writes them, CTRL, ENTER, and keys held with a click or a scroll are held.

Python
from openai import ComputerToolset, OpenAI
from pethost_toolsets import OpenAIComputer

toolset = ComputerToolset(OpenAIComputer(sandboxes, sandbox.sandbox_id))
response = toolset.run(
    OpenAI(),
    {"model": "gpt-6.2-sol", "input": "Open Chrome, go to pethost.dev and tell me the page's heading."},
    max_steps=50,
)
print(response.output_text)
TypeScript
import OpenAI from "openai";
import { ComputerToolset } from "openai/helpers/computer";
import { OpenAIComputer } from "pethost-toolsets/openai/computer";

const toolset = new ComputerToolset(new OpenAIComputer({ sandboxes, sandboxId }));
const response = await toolset.run(
  new OpenAI(),
  { model: "gpt-6.2-sol", input: "Open Chrome, go to pethost.dev and tell me the page's heading." },
  { maxSteps: 50 },
);
console.log(response.output_text);

Step 5: Give OpenAI's model the browser

OpenAIBrowser is a driver of its BrowserToolset, which reads pages as accessibility trees and acts on their elements by ref, in tabs. connect reaches the sandbox's Chrome as ClaudeBrowser does. The toolset asks confirm before every action that changes a page, and url_policy before every address the model opens.

Python
from openai.lib.browser import BrowserToolset
from openai.lib.responses_tool_runner import ResponsesToolRunner
from pethost_toolsets import OpenAIBrowser

with OpenAIBrowser.connect(sandboxes, sandbox.sandbox_id) as browser:
    toolset = BrowserToolset(
        browser,
        confirm=lambda context: True,
        url_policy=lambda context, url: url.startswith("https://pethost.dev/"),
    )
    response = ResponsesToolRunner(browser=toolset).run(
        OpenAI(),
        {"model": "gpt-6.2-astra", "input": "Open pethost.dev/sandboxes and say what a sandbox costs."},
        max_steps=40,
    )
    print(response.output_text)
TypeScript
import { BrowserToolset } from "openai/helpers/browser";
import { ResponsesToolRunner } from "openai/helpers/responses-tool-runner";
import { OpenAIBrowser } from "pethost-toolsets/openai/browser";

const browser = await OpenAIBrowser.connect({ sandboxes, sandboxId });
const toolset = new BrowserToolset(browser, {
  confirm: () => true,
  urlPolicy: (_, url) => url.startsWith("https://pethost.dev/"),
});
try {
  const response = await new ResponsesToolRunner({ browser: toolset }).run(
    new OpenAI(),
    { model: "gpt-6.2-astra", input: "Open pethost.dev/sandboxes and say what a sandbox costs." },
    { maxSteps: 40 },
  );
  console.log(response.output_text);
} finally {
  toolset.close();
  await browser.close();
}

Step 6: Let OpenAI's model act by code

OpenAI recommends computer use by code for GPT-6 Astra: the model writes Python, which drives the desktop with PyAutoGUI, or JavaScript, which drives its Chrome with Playwright. OpenAICode hands it the two tools, exec_py and exec_js, and runs each call in the sandbox's code runtime, where each language is a session that keeps its variables from one call to the next.

Python
from openai.lib.responses_tool_runner import ResponsesToolRunner
from pethost_toolsets import OpenAICode

with OpenAICode(sandboxes, sandbox.sandbox_id) as code:
    response = ResponsesToolRunner(functions=code.functions).run(
        OpenAI(),
        {"model": "gpt-6-astra", "input": "Open pethost.dev in the browser and tell me the page's heading."},
        max_steps=50,
    )
    print(response.output_text)
TypeScript
import { ResponsesToolRunner } from "openai/helpers/responses-tool-runner";
import { OpenAICode } from "pethost-toolsets/openai/code";

const code = new OpenAICode({ sandboxes, sandboxId });
try {
  const response = await new ResponsesToolRunner({ functions: code.functions }).run(
    new OpenAI(),
    { model: "gpt-6-astra", input: "Open pethost.dev in the browser and tell me the page's heading." },
    { maxSteps: 50 },
  );
  console.log(response.output_text);
} finally {
  await code.close(); // stops the sessions; the desktop and Chrome run on
}

Step 7: Watch it, or take over

The drivers act on the desktop a desktop link shows: CreateLink with desktop opens it live in a browser, with view_only to watch without touching, and the console's Desktop tab shows it too (computer use). A person can sign in to a site there, and the model goes on from the page they left.

The drivers

DriverForActs through
ClaudeComputerClaude's computer toolset, computer_toolset_20260801ControlDesktop, one call an action
ClaudeBrowserClaude's browser toolset, browser_toolset_20260801Playwright, over a browser link to the sandbox's Chrome
OpenAIComputerThe openai SDK's ComputerToolset, OpenAI's computer toolControlDesktop, one call an action
OpenAIBrowserThe openai SDK's BrowserToolsetPlaywright, over a browser link to the sandbox's Chrome
OpenAICodeOpenAI's computer use by code, exec_py and exec_jsThe sandbox's code runtime, one RunCommand a call

Python has each as a class for asyncio too, AsyncClaudeComputer, AsyncOpenAICode and the others, over an AsyncSandboxes. The browser drivers serve the toolsets' members that Playwright can carry out: not find, which needs a model to match words to elements, nor file uploads, as the browser is not on the machine your files are. The packages are pethost-toolsets on PyPI and on npm, and their source and an example program for each driver are at github.com/pethost-dev/toolsets.

What the model is told

An action the desktop refuses, such as a point off the screen or a key it does not know, reaches Claude as the tool's error, in the desktop's words, and Claude can try again; a page that refuses an action reaches either model's browser tool the same way. OpenAI's computer tool answers the model with a screenshot alone, so OpenAIComputer raises DesktopRefusedError, with the desktop's failure, and the run ends there. A run of code answers the model with what the code printed, logged and displayed, an error's traceback, or the runtime's words when it could not run the code. A browser link the server refuses, such as a stopped sandbox's, raises BrowserConnectionError with the server's words.

Keep the browser's keys to yourself

A browser link opens the whole browser and every site it is signed in to. The drivers hand it to Playwright alone and keep it, and the sandbox's token, out of every tool result, error and log line; keep them out of your own logs too. A page can show text written to steer an agent, so give a sandbox that browses no more secrets and no wider egress than the task needs (secrets and egress). A template saved from a sandbox keeps Chrome's profile, its sign-ins included (the profile, sign-ins and templates).

While a browser driver is connected, the connection is a session: the sandbox does not pause, so close the driver when the work is done. The computer drivers hold nothing open, and the code runtime's sessions wait in the sandbox, which pauses after its idle time between two runs, sessions and all.

When it does not work

  • The first action takes seconds: it started the desktop. The next ones answer at once.
  • ModuleNotFoundError naming an extra: a Python driver needs its provider's extra, and a browser driver browser too: pip install 'pethost-toolsets[openai,browser]' for OpenAIBrowser.
  • The SDK asks for confirm: the Anthropic SDK requires one while type, key or hold_key is on, and the openai SDK's BrowserToolset for any member that changes a page, and a url_policy for navigate. Pass your own check, or one that allows everything for a sandbox that holds nothing of yours.
  • DesktopRefusedError with OpenAI: its failure says why: OFF_SCREEN for a point outside the screen, UNKNOWN_KEY for a key name the desktop does not know.
  • A run of code says the session was stopped: its code ran past timeout_seconds and did not stop, and the session's variables went with it. The next call starts a new session.
  • The sandbox does not pause: a browser driver is still connected. Close it.

Questions

Can Claude use a Pethost sandbox as its computer?

Yes: ClaudeComputer gives Claude's computer toolset the sandbox's desktop, and ClaudeBrowser gives the browser toolset its Chrome.

Does it work with OpenAI's computer use?

Yes, all three ways OpenAI's guide gives: OpenAIComputer and OpenAIBrowser drive the sandbox for the openai SDK's ComputerToolset and BrowserToolset, and OpenAICode runs the model's code in the sandbox.

What is computer use by code?

The model writes code that drives the computer, Python with PyAutoGUI or JavaScript with Playwright, rather than one action at a time; the sandbox's code runtime runs it and keeps its variables for the next call (computer use by code).

Which languages are there?

Python and TypeScript, as pethost-toolsets on PyPI and npm.

Do the drivers cost anything?

No: they are free and open source, under the MIT license. The sandbox is billed by the second as any other, and the model by its provider.

Can I use Playwright myself instead?

Yes: a browser link gives Playwright or Puppeteer the same Chrome (browser automation).

Try Pethost Agent Sandboxes

A 7-day trial with $1 of usage and 4 vCPUs, with a card. Then a plan from $20 a month, which includes as much usage.

Start the trial