Suryanand/ Bootcamp
suryanand.com ↗Let's talk
← AgentsAI guideAdvanced#agents#computer-use#browser-automation#playwright
Frame · ai-engineering / agents / 10-computer-use-and-browser-agents.mdGuide 034 / 103

Computer-use and browser agents

Most software was built for humans with a mouse and keyboard, not for APIs. Computer-use agents close that gap: the model looks at a screenshot, decides where to click or what to type, and your code performs the action and sends back a new screenshot. Browser agents are a narrower, often more reliable cousin that drive a web browser through its DOM or accessibility tree. Both are powerful, both are slow compared to an API call, and both need more sandboxing than any other kind of agent.

Why it matters

Plenty of valuable work lives behind interfaces with no API: legacy back-office tools, supplier portals, internal admin screens, desktop apps. A computer-use agent can fill forms, reconcile data across systems, and test your own UI end to end, without anyone writing an integration first.

The major providers all offer something here. Anthropic's Claude has a computer-use toolset, OpenAI's Responses API has a computer-use tool, and Google offers a Gemini Computer Use model through the Gemini API that is focused on browser control. In every case the model only proposes actions; your application executes them in an environment you control. That design is what lets you sandbox it.

How it works

Screenshot loop (computer use). You give the model a goal and a screenshot. It returns an action such as left_click at a coordinate, type some text, scroll, key a shortcut, or screenshot to look again. You execute the action in a virtual machine or container and return the result, usually a fresh screenshot. Repeat until the task is done.

In the current Claude API, you enable this with the computer_toolset_20260801 toolset. Each tool_use block has the member action as its name (for example screenshot or left_click), its arguments in input, and "toolset_name": "computer"; your tool_result must echo that toolset name. Coordinates are in the pixel space of the screenshots you send, so if you downscale screenshots you must scale clicks back up. The docs recommend modest resolutions such as 1280x800 for web apps. A zoom action lets the model inspect a region at full resolution.

DOM or accessibility loop (browser agents). Instead of pixels, the agent sees a structured snapshot of the page and acts on element references. Microsoft's Playwright MCP server works this way: it exposes browser automation through accessibility snapshots, so no vision model is needed and element targeting is more deterministic. This is usually faster and cheaper, but it cannot see canvas-rendered content or visual-only cues.

Rendering diagram…

Reference architecture

Rendering diagram…

The VM is disposable and holds no real credentials. Network egress goes through an allowlist. Consequential actions (purchases, form submissions, accepting terms) require a human.

Code

A trimmed Python harness for Claude's computer-use toolset. The executor functions are stubs you would implement with something like xdotool inside a container, or Playwright for a browser-only environment.

import base64
import anthropic

client = anthropic.Anthropic()

def take_screenshot() -> str:
    with open("/tmp/screen.png", "rb") as f:  # captured inside the sandbox
        return base64.standard_b64encode(f.read()).decode()

def perform(action: str, args: dict) -> None:
    print("executing", action, args)  # call xdotool or Playwright here

RISKY = {"type"}  # e.g. require confirmation before typing into forms

def run(goal: str, max_steps: int = 25) -> None:
    messages = [{"role": "user", "content": goal}]
    for _ in range(max_steps):
        resp = client.messages.create(
            model="claude-opus-5-5",
            max_tokens=1024,
            tools=[{"type": "computer_toolset_20260801"}],
            messages=messages,
        )
        messages.append({"role": "assistant", "content": resp.content})
        if resp.stop_reason != "tool_use":
            print("done:", [b.text for b in resp.content if b.type == "text"])
            return

        results = []
        for block in resp.content:
            if block.type != "tool_use":
                continue
            if block.name in RISKY and input(f"Allow {block.name} {block.input}? [y/N] ") != "y":
                content = "User declined this action."
            elif block.name in ("screenshot", "zoom"):
                content = [{"type": "image", "source": {
                    "type": "base64", "media_type": "image/png", "data": take_screenshot()}}]
            else:
                perform(block.name, block.input)
                content = "OK"
            results.append({"type": "tool_result", "tool_use_id": block.id,
                            "toolset_name": "computer", "content": content})
        messages.append({"role": "user", "content": results})

run("Open the staging admin site and export last week's orders as CSV.")

For a real zoom, crop the requested region before encoding. Check the current docs for the toolset version your model supports, since these identifiers are dated and change over time.

Trade-offs and pitfalls

  • Prompt injection is the top risk. Every web page and document the agent sees can contain instructions. Anthropic runs classifiers on screenshots to flag likely injections, but you still need isolation, allowlists and human confirmation for consequential actions.
  • No real credentials in the sandbox. Anthropic's guidance is to avoid giving the model account logins or sensitive data. Pre-authenticate sessions with scoped test accounts where you can.
  • Slow and expensive. Each step is a model call with an image. Prefer an API, then a DOM-based browser agent, and use pixels only when you must.
  • Coordinate bugs. High-DPI displays and downscaled screenshots cause clicks to land in the wrong place. Scale consistently and test on the resolution you deploy.
  • Flaky UIs. Pop-ups, cookie banners and slow loads derail runs. Add waits, retry with a fresh screenshot, and cap steps.
  • Non-reproducibility. Record sessions (screenshots plus actions) so you can replay and debug failures.

Checklist

  • Prefer a real API or a DOM-based browser agent before pixel-level computer use.
  • Run in a disposable VM or container with least privilege.
  • Restrict network egress to an allowlist of domains.
  • Never place real passwords, payment details or personal data in the environment.
  • Require human confirmation for purchases, submissions and agreeing to terms.
  • Cap steps and wall-clock time per task.
  • Record every screenshot and action for audit and replay.

Further reading

Why this exists README

I learn best by explaining things, so I record the explanations. Everything here is free, with no sign-up. If a lesson helps you ship something, I'd love to hear about it.