Courses / Agentic AI / Module 13
Module 13: Browser and computer-use agents
10 h · theory 3 · hands-on 4 · project 2 · revision 1
You will be able to
- Drive a browser with Playwright from an agent
- Use a browser agent framework safely
- Sandbox and approve every submit
Capstone increment: Optional: a browser tool that reads a status page, sandboxed and approval-gated.
Job-description skills: Browser automation · Lab tools: playwright, browser-use
1. When there is no API
Some systems only have a web interface: a vendor’s status page, an old admin console, a government portal. Browser agents read and act on pages the way a person does, and computer-use agents do the same on a whole desktop from screenshots. They are powerful and the least reliable tool in this course, so use them only where nothing better exists.
The loop is the agent loop with a browser as the tool: observe the page, decide an action, execute it with Playwright in an isolated profile, observe again. Guards decide which actions run and which wait for a person.
2. Seeing the page
There are two ways for a model to see a page. The accessibility tree (roles, names and states of elements) is compact text with stable references; Microsoft’s Playwright MCP server gives agents accessibility snapshots this way. Screenshots let a vision model see layout, canvas charts and anything the tree misses, at a higher token cost and with coordinate-based clicks.
Most robust agents combine them: the tree for finding and acting on elements, a screenshot when the tree isn’t enough. Prefer selectors by role and visible text over brittle CSS paths.
3. Frameworks and computer-use APIs
browser-use wraps Playwright in an agent loop with page state extraction; Playwright MCP exposes browser actions as MCP tools any host can use. Anthropic’s computer use and OpenAI’s computer-using agent let models drive a full virtual desktop from screenshots, with reference implementations that run in a container.
For known flows, write a deterministic Playwright script and let the agent call it as one tool. Use the open-ended browser agent only for exploration and unpredictable pages.
4. Safety
Every page the agent reads is untrusted input, and hidden text on a page is a classic injection. Run the browser in an isolated container and a fresh profile with no saved logins, restrict navigation to an allow-list of domains, block downloads by default, and hold every submit, purchase, send and sign-in for human approval.
Never put credentials or payment details in the page or the prompt. If a flow needs login, have a person sign in, or give the tool a dedicated, minimal account whose credentials the tool holds and the model never sees.
5. Make it reliable enough
Expect failures from pop-ups, slow loads, layout changes and A/B tests. Wait for elements rather than sleeping, retry idempotent reads, take a screenshot on failure, and cap steps and time per task. Evaluate on a fixed set of recorded pages or a staging site so changes are measured, not guessed.
For the capstone, a browser tool that reads a vendor status page, sandboxed and approval-gated, is enough to show you can do this safely.
Hands-on: coding window
The coding window and the full VS Code lab are available after you sign in.
Sign in to codeLabs
Lab 13.1: Deterministic first
Write a Playwright script that reads a public status page and returns component states as JSON, with role-based selectors and a recorded trace.
Expected: A tool that returns structured status in under 5 seconds, and its trace file.
Lab 13.2: A contained browser agent
Run browser-use (or a Playwright MCP host) in Docker with a fresh profile, a domain allow-list and no downloads; give it a task on an unfamiliar status page.
Expected: A run log showing allowed and blocked actions, including one blocked navigation.
Lab 13.3: Browser tool (optional capstone increment)
Add a read_status_page tool to the capstone that uses the script for known vendors and the agent for others, with every submit held for approval.
Expected: Incident runs cite the vendor’s status; no submit happens without approval.
Go deeper
Videos
- Anthropic Computer Use - Hands On Tutorial · Sam Witteveen · ~9 min. A hands-on tutorial of Anthropic’s computer use with the reference container.
- Playwright MCP: How AI Agents Can Control Your Browser · Playwright · ~2 min. How Playwright MCP lets agents drive a browser through accessibility snapshots.
- Claude | Computer use for automating operations · Anthropic · ~2 min. A short demo of computer use automating an operations task.
Further reading
- Paper WebArena: A Realistic Web Environment for Building Autonomous Agents · Zhou et al., 2023. Self-hosted websites and functional grading for web agents.
- Paper OSWorld: Benchmarking Multimodal Agents for Open-Ended Tasks in Real Computer Environments · Xie et al., 2024. Computer-use tasks across real apps, and how far agents are from people.
- Docs Computer use tool · Anthropic docs. Screenshot, mouse and keyboard actions, the agent loop and the safety guidance.
- Docs Playwright for Python · Playwright docs. The browser automation library under most browser agents.
GitHub repositories
- microsoft/playwright-python: Locators by role and text, auto-waiting, and the tracing API.
- microsoft/playwright-mcp: Browser tools over MCP using accessibility snapshots; read its tool list.
- browser-use/browser-use: How it extracts page state for the model and which actions it exposes.
- anthropics/claude-quickstarts: The computer-use demo: a containerised desktop and the agent loop around it.
Checkpoint quiz
Interview questions
- When would you use a browser agent instead of an API integration?
- Compare accessibility-tree and screenshot approaches for browser agents.
- How do you secure an agent that browses the open web?
- How do you make a browser agent reliable enough for production?
- Design a tool that reads vendor status pages for an ops assistant.
Ask the professor
Sign in to ask questions about this module.
Discussion
Community discussion appears here once giscus is configured (see README).