Building a computer-use agent
Some agents work through a screen: they look at a screenshot, then click and type. Learn the loop, why it must run in a sandbox, and where to ask for confirmation.
In 60 seconds
Building a computer-use agent
Some agents work through a screen: they look at a screenshot, then click and type. Learn the loop, why it must run in a sandbox, and where to ask for confirmation.
The screenshot-action loop
- 1
Screenshot
Capture the screen (or the browser page) and send it to the model with the goal. - 2
Decide
The model returns one action: click at (x, y), type text, press a key, scroll, or done. - 3
Check
Your code checks the action against rules: allowed site? needs confirmation? inside limits? - 4
Act
Your code performs the action in the sandboxed browser or virtual machine. - 5
Repeat
Take a new screenshot and loop, with a step limit and a time limit.
RISKY_WORDS = ("pay", "submit", "delete", "send", "confirm", "transfer")
ALLOWED_SITES = ("https://example-test-portal.local",)
def take_screenshot() -> bytes: return b"" # placeholder: sandbox screen
def current_url() -> str: return ALLOWED_SITES[0] # placeholder
def call_model(goal: str, image: bytes) -> dict: # placeholder: your provider
return {"action": "done", "summary": "demo"}
def perform(action: dict) -> None: pass # placeholder: sandbox input
def ask_human(question: str) -> bool:
return input(question + " [y/N] ").strip().lower() == "y"
def run(goal: str, max_steps: int = 30) -> str:
for step in range(max_steps):
if not current_url().startswith(ALLOWED_SITES):
return "Stopped: left the allowed sites"
action = call_model(goal, take_screenshot())
if action["action"] == "done":
return action.get("summary", "done")
label = str(action.get("target_label", "")).lower()
if any(word in label for word in RISKY_WORDS):
if not ask_human("Agent wants to: " + str(action) + ". Allow?"):
return "Stopped: person declined a risky action"
perform(action)
return "Stopped: step limit reached"
print(run("Download last month's electricity bill as PDF"))Run it in a sandbox
- Use a separate virtual machine or container with a fresh browser, not your own laptop session.
- No saved passwords, no personal email, no logged-in banking in that browser.
- Limit network access to the sites the task needs.
- Log in with a test or limited account where possible. If a real login is needed, let the person do that part themselves.
- Reset the machine after each task so nothing carries over.
Where to ask for confirmation
| Action | Confirm? | Why |
|---|---|---|
| Scrolling, reading, clicking menus | Usually no | Easy to undo and low risk. |
| Filling a search box | Usually no | Low risk, unless it sends personal data. |
| Entering personal data into a form | Yes | Personal data leaves the user's control. |
| Submit, pay, send, delete, accept terms | Always | Hard or impossible to undo. |
| Entering passwords or card numbers | Never let the agent do it | The person should do this part themselves. |
Making it work better
- Screenshots and screen coordinates must match. If you resize images before sending them, scale the model's coordinates back.
- Wait for pages to load before taking the next screenshot; many failures are just timing.
- Where a website offers an API or an accessibility tree, text-based page reading is often more reliable and cheaper than pixels.
- Expect slowness: each step needs a screenshot and a model call. Computer use is for tasks with no better interface.
Watch and read more
Lab
A safety design for a computer-use agent: sandbox setup, allow-list, confirmation table and stop rules.
The problem
Design, on paper, a computer-use agent that downloads a family's monthly electricity bill from a utility website and saves it to a folder.
- Describe the sandbox: where it runs, what the browser contains, which sites it can reach.
- Write down the steps a person takes. Mark each as agent alone, agent with confirmation or person only.
- Write three stop rules (for example: left the allowed site, step limit, unexpected pop-up asking for data).
- Explain how the login happens without the agent seeing the password.
You are done when
Hard questions
Try to answer before you reveal. If you can answer these, you understood the lesson.
Q1The utility site adds a pop-up: "Pay pending amount now to download your bill". What should your agent do, and why?Reveal
Stop and hand over to the person. The task was to download a bill, not to pay. The pop-up may be real or a trick, but either way it asks for an action outside the goal that involves money. The agent should report what it saw and let the person decide.
Q2Why is a keyword check like "pay" or "submit" on button labels not enough to catch risky actions?Reveal
Labels vary ("Proceed", "Continue", icons with no text, other languages), and a page could label a risky button harmlessly on purpose. Combine several controls: a site allow-list, confirmation for any form submission or data entry, network limits in the sandbox, test accounts with low limits, and the model flagging uncertain steps. Assume any single check will miss something.
Questions people ask
Why not just use a browser automation script instead?
If the steps are fixed and the page rarely changes, a normal script (for example with a browser automation library) is cheaper, faster and more reliable. Computer-use agents help when pages change, layouts vary, or the task needs judgement. Many teams use scripts for the fixed parts and an agent only where needed.
Can the agent solve CAPTCHAs?
It should not try. CAPTCHAs exist to stop automated use, and bypassing them can break a site's terms. Have the agent stop and hand over to the person.
Is it safe to run a computer-use agent on my own laptop?
It is risky. Your laptop has your logins, files and messages, and the agent could be tricked into using them. Use a separate virtual machine or container with a clean browser and limited network.
How do I debug a computer-use agent?
Save every screenshot with the action the model chose and the reason it gave. Replaying these frames usually shows the problem quickly: a page still loading, a pop-up, or a click a few pixels off.
Lesson test
5 questions. Get 3 right (60%) to pass and complete this lesson.