---
title: "Computer-use environments for AI agents"
description: "Hosted computer-use episodes: a play_url your agent's own browser opens, for Claude computer use, OpenAI's computer-use tool, Browser Use or Playwright. The same tasks and verifiers as tool use."
source: https://sandworld.dev/docs/computer-use
---

# Computer use

Every twin has a visual app, and every tap in it becomes the same tool call an API agent makes. A hosted computer-use episode gives your agent the app instead of the tools: a `play_url` that its own browser opens, with no Sandworld sign-in. The agent works the app through the screen and clicks Done, and the task's own verifier grades the result exactly as it grades a tool-use episode, so the same model can be compared across interfaces on the same tasks. Sandworld runs no browser: yours does.

## Get a play_url

Start an episode as usual, with `"mode": "computer-use"`. An API key is optional, as for the sandbox; with one, the episode belongs to your workspace.

```bash
curl -s https://sandworld.dev/api/v1/environments/quickbasket/episodes \
  -H "Authorization: Bearer $SANDWORLD_API_KEY" -H "content-type: application/json" \
  -d '{"task_id": "qb-01", "seed": 1, "mode": "computer-use", "agent_name": "my-cua"}'
```

```json
{
  "episode_id": "ep_kFuMw9ZdlTcLrloi",
  "environment": "quickbasket",
  "task_id": "qb-01",
  "seed": 1,
  "instruction": "Order 2 cartons of Whole Milk (1 L) and one 12-pack of Free-Range Eggs. …",
  "policy": "You are acting for the Quickbasket customer Jordan Lee …",
  "mode": "computer-use",
  "surface": "mobile",
  "play_url": "https://sandworld.dev/play/quickbasket?episode=ep_kFuMw9ZdlTcLrloi#token=swpt_…",
  "play_url_expires_at": "2026-11-22T12:40:50.409Z",
  "next": { "submit": "/api/v1/episodes/ep_kFuMw9ZdlTcLrloi/submit", "episode": "/api/v1/episodes/ep_kFuMw9ZdlTcLrloi" }
}
```

The response has no tool list. Give the `instruction` (and the `policy`, if your agent should follow it) to your agent, and open the `play_url` in its browser. The token after `#` stays in the browser: it is never sent to a server, so it can't end up in an access log. Treat the whole URL as a secret anyway, and don't log it.

```python
from sandworld import Sandworld   # pip install https://sandworld.dev/files/sandworld-python.tar.gz

sw = Sandworld()                    # SANDWORLD_API_URL=https://sandworld.dev/api/v1, SANDWORLD_API_KEY
ep = sw.computer_episode("quickbasket", "qb-01", seed=1, agent_name="my-cua")
print(ep.instruction)               # the task, for your agent's prompt
print(ep.play_url)                  # open it in your agent's browser; the #token is a secret
...
verdict = ep.submit()               # if the agent didn't click Done; returns the same verdict either way
print(verdict.passed, verdict.failed_checks)
```

## The page

- **The app** — a phone twin as a 390-pixel-wide phone at the left (up to 844 pixels tall), a web twin across the page. A browser window of 1280×800 fits both.
- **Done: submit for grading** — beside the phone, or in a bar above a web app. It closes the episode and shows the verdict and the checks.
- **Message to the user** — on tasks with a simulated user, a box for asking a question; the reply appears under it. Each message is an `ask_user` call on the episode, as for tool use.

Every control has a role and an accessible name, so agents that read the accessibility tree (Playwright's `get_by_role`, an ARIA snapshot) work as well as agents that read pixels. The app is inside `[data-twin-root]` and the episode controls inside `[data-sandworld-controls]`.

## Claude computer use

With the Messages API's computer toolset (`computer_toolset_20260801`, no beta header) and a Playwright browser. Claude names each action as its own tool call, and each result echoes `toolset_name`. This browser has nothing to zoom, so the example turns `zoom` off.

```python
import base64, anthropic
from playwright.sync_api import sync_playwright
from sandworld import Sandworld

ep = Sandworld().computer_episode("quickbasket", "qb-01", seed=1, agent_name="claude-opus-5-5")
PROMPT = f"""You are using a web app in a browser. {ep.instruction}
Follow this policy: {ep.policy}
Work only through the app on the screen. When the task is finished, click "Done: submit for grading"."""
KEYS = {"Return": "Enter", "ctrl": "Control", "alt": "Alt", "shift": "Shift", "super": "Meta", "BackSpace": "Backspace",
        "Page_Down": "PageDown", "Page_Up": "PageUp", "Up": "ArrowUp", "Down": "ArrowDown", "Left": "ArrowLeft", "Right": "ArrowRight"}

client = anthropic.Anthropic()
with sync_playwright() as p:
    page = p.chromium.launch().new_page(viewport={"width": 1280, "height": 800})
    page.goto(ep.play_url)

    def screenshot():
        return [{"type": "image", "source": {"type": "base64", "media_type": "image/png",
                                             "data": base64.b64encode(page.screenshot()).decode()}}]

    def run(action, i):   # one member of the computer toolset; coordinates are screenshot pixels
        x, y = i.get("coordinate", (0, 0))
        if action == "screenshot": return screenshot()
        if action == "left_click": page.mouse.click(x, y)
        elif action == "double_click": page.mouse.dblclick(x, y)
        elif action == "right_click": page.mouse.click(x, y, button="right")
        elif action == "mouse_move": page.mouse.move(x, y)
        elif action == "type": page.keyboard.type(i["text"])
        elif action == "key":
            for _ in range(i.get("repeat", 1)):
                page.keyboard.press("+".join(KEYS.get(k, k) for k in i["text"].split("+")))
        elif action == "scroll":
            page.mouse.move(x, y)
            dx, dy = {"up": (0, -1), "down": (0, 1), "left": (-1, 0), "right": (1, 0)}[i["scroll_direction"]]
            page.mouse.wheel(dx * 100 * i["scroll_amount"], dy * 100 * i["scroll_amount"])
        elif action == "wait": page.wait_for_timeout(1000 * i.get("duration", 1))
        else: raise ValueError(f"{action} isn't supported here")
        page.wait_for_timeout(300)
        return [{"type": "text", "text": "OK"}]

    messages = [{"role": "user", "content": PROMPT}]
    for _ in range(80):
        response = client.messages.create(
            model="claude-opus-5-5", max_tokens=16000, messages=messages,
            tools=[{"type": "computer_toolset_20260801", "configs": {"zoom": {"enabled": False}}}],
        )
        messages.append({"role": "assistant", "content": response.content})
        calls = [b for b in response.content if b.type == "tool_use"]
        if not calls:
            break
        results = []
        for b in calls:
            try:
                results.append({"type": "tool_result", "tool_use_id": b.id, "toolset_name": "computer", "content": run(b.name, b.input)})
            except Exception as e:
                results.append({"type": "tool_result", "tool_use_id": b.id, "toolset_name": "computer", "content": f"Error: {e}", "is_error": True})
        messages.append({"role": "user", "content": results})

print(ep.submit().passed)   # the verdict, whether Claude clicked Done or ran out of turns
```

## OpenAI computer use

With the Responses API's `computer` tool. Each `computer_call` carries a list of actions; the reply is a screenshot, chained with `previous_response_id`.

```python
import base64
from openai import OpenAI
from playwright.sync_api import sync_playwright
from sandworld import Sandworld

ep = Sandworld().computer_episode("quickbasket", "qb-01", seed=1, agent_name="gpt-6.2-sol")
PROMPT = f"""You are using a web app in a browser. {ep.instruction}
Follow this policy: {ep.policy}
Work only through the app on the screen. When the task is finished, click "Done: submit for grading"."""
client = OpenAI()
with sync_playwright() as p:
    page = p.chromium.launch().new_page(viewport={"width": 1280, "height": 720})
    page.goto(ep.play_url)

    def do(a):
        t = a["type"]
        if t == "click": page.mouse.click(a["x"], a["y"], button=a.get("button", "left"))
        elif t == "double_click": page.mouse.dblclick(a["x"], a["y"])
        elif t == "scroll": page.mouse.move(a["x"], a["y"]); page.mouse.wheel(a.get("scroll_x", 0), a.get("scroll_y", 0))
        elif t == "type": page.keyboard.type(a["text"])
        elif t == "keypress": page.keyboard.press("+".join(a["keys"]))
        elif t == "move": page.mouse.move(a["x"], a["y"])
        elif t == "wait": page.wait_for_timeout(2000)
        # "screenshot" needs nothing: every computer_call_output carries one

    response = client.responses.create(model="gpt-6.2-sol", tools=[{"type": "computer"}], input=PROMPT)
    for _ in range(80):
        calls = [item for item in response.output if item.type == "computer_call"]
        if not calls:
            break
        outputs = []
        for call in calls:
            for action in call.actions:
                do(action.model_dump())
            shot = base64.b64encode(page.screenshot()).decode()
            outputs.append({"type": "computer_call_output", "call_id": call.call_id,
                            "output": {"type": "computer_screenshot", "image_url": f"data:image/png;base64,{shot}", "detail": "original"}})
        response = client.responses.create(model="gpt-6.2-sol", tools=[{"type": "computer"}],
                                           previous_response_id=response.id, input=outputs)

print(ep.submit().passed)
```

## Browser Use

Browser Use takes the starting URL in the task text.

```python
# pip install browser-use   (1.x, Python 3.11+)
import asyncio
from browser_use import Agent, ChatAnthropic
from sandworld import Sandworld

async def main():
    ep = Sandworld().computer_episode("ledgerline", "ll-01", seed=1, agent_name="browser-use")
    task = (f"Open {ep.play_url} . {ep.instruction} Follow this policy: {ep.policy} "
            'Work only through the app on the page. When the task is finished, click "Done: submit for grading".')
    agent = Agent(task=task, llm=ChatAnthropic(model="claude-sonnet-5-5"))
    await agent.run()
    print(ep.submit().passed)

asyncio.run(main())
```

## Plain Playwright

For your own agent loop, or a scripted check. Find controls by role and name; the verdict appears on the page after Done.

```python
# pip install playwright && playwright install chromium
from playwright.sync_api import sync_playwright
from sandworld import Sandworld

ep = Sandworld().computer_episode("quickbasket", "qb-01", seed=1, agent_name="scripted")
with sync_playwright() as p:
    page = p.chromium.launch().new_page(viewport={"width": 1280, "height": 800})
    page.goto(ep.play_url)
    app = page.locator("[data-twin-root]")             # the app; the episode controls sit beside it
    app.get_by_role("button", name="Search", exact=True).click()
    app.get_by_role("textbox", name="Search products").fill("Whole Milk")
    app.get_by_role("textbox", name="Search products").press("Enter")
    app.get_by_role("button", name="Add Whole Milk", exact=True).click()
    # … the rest of the order: your agent decides each step from the screen or the accessibility tree
    page.get_by_role("button", name="Done: submit for grading").click()
    page.locator("[data-sandworld-verdict]").wait_for()   # "pass" or "fail"; the page lists the checks
    print(page.locator("[data-sandworld-verdict]").get_attribute("data-sandworld-verdict"))
```

## How grading works

- Each tap, form and message in the app is a tool call on the episode, recorded in order, as if an API agent had made it. Opening a screen that shows a record is the lookup.
- Done (or `POST /api/v1/episodes/<id>/submit`) closes the episode and runs the task's verifier on the app's final state and the call log: the same checks as tool use, including whether the agent looked before acting, asked when it had to, and left everything else alone.
- The verdict shows on the page and at `GET /api/v1/episodes/<id>` (`status` becomes `submitted`, `result` holds the checks). An episode that is never submitted is never graded.

## Limits

| What | Limit |
| --- | --- |
| play_url | Opens one episode, for 2 hours from the start call. Only a hash of its token is stored; it can't be shown again. |
| Starting episodes | 60 an hour per address without an API key, 2,000 an hour per API key, shared with tool-use episodes. |
| Tool calls | 200 per episode, as for tool use; the page's calls also count against 3,000 an hour per address. |
| Tasks | A task_id is required. Step signals (signals: true) aren't available; fault_profile and user_simulator work. |
| After Done | The app stays on screen but takes no more input; submitting again returns the same verdict. |

Sandworld checks the tasks this way: a script carries out each task's reference solution through the app alone, on the hosted pages too, and the verifier grades it. That is how we know the tasks can be done through the screen.

## Measure the GUI tax

Sandworld's harness runs models through the screen in three modes — `gui-ax` (element list and text), `gui-screenshot` and `gui-som` (marked screenshot) — with the same prompt, policy and verifiers as tool use. It drives a headless browser and hands the model observations: the element list (Set-of-Marks numbers, roles, names, boxes), the visible text, and optionally a screenshot with the numbers drawn on. Results appear on the [Arena](https://sandworld.dev/arena) labelled by interface.

For your own agent, run the same tasks and seeds once through the tools (an ordinary episode, or [a benchmark run](https://sandworld.dev/docs/benchmarks)) and once as computer-use episodes, and compare the verdicts: the same verifier grades both. To have your model run through Sandworld's screen harness, [ask us](https://sandworld.dev/contact?intent=score).

## References

- [Claude: computer use tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/computer-use-tool) and the [reference implementation](https://github.com/anthropics/claude-quickstarts/tree/main/computer-use-demo)
- [OpenAI: computer use](https://developers.openai.com/api/docs/guides/tools-computer-use)
- [Browser Use: quickstart](https://docs.browser-use.com/quickstart)
- [Playwright: locators](https://playwright.dev/python/docs/locators)
