Computer use is a way for an AI model to operate a graphical interface by looking at screenshots and returning mouse and keyboard actions, which a program then performs. This article covers the mechanics a developer has to build: the loop, the coordinate systems, the input layer, and the checks that keep it reliable. For what a computer-use agent is and why it needs its own desktop, see what is a computer-use agent.
What does the computer-use loop look like in code?
The computer-use loop is screenshot, model call, action, repeat, with a step limit. The model never touches the machine; your harness does.
The following Python sketch shows the shape. It is an example: call_model stands for whatever model API you use, and the action format is one you define.
import pyautogui
MAX_STEPS = 30
SCREEN_W, SCREEN_H = pyautogui.size()
for step in range(MAX_STEPS):
image = pyautogui.screenshot() # what the model will see
action = call_model(task, image, history) # e.g. {"type": "click", "x": 640, "y": 360}
if action["type"] == "done":
break
if action["type"] == "click":
pyautogui.click(action["x"], action["y"])
elif action["type"] == "type":
pyautogui.write(action["text"])
elif action["type"] == "key":
pyautogui.hotkey(*action["keys"]) # e.g. ["ctrl", "s"]
history.append(action)
Benchmarks use the same contract. OSWorld's actions are Python calls to "the widely used mouse and keyboard control library pyautogui", plus three special actions, WAIT, FAIL and DONE (OSWorld paper, section 2.4, read 2026-11-26).
How do screen coordinates work?
Screen coordinates count pixels from the top-left corner, with x growing to the right and y growing down. The pyautogui documentation states it directly: "The pixel at the top-left corner is at coordinates 0, 0. If your screen's resolution is 1920 x 1080, the pixel in the lower right corner will be 1919, 1079" (pyautogui mouse documentation, read 2026-11-26).
A model returns a point in the coordinate system of the image it was shown. That is often not the screen's coordinate system, for two reasons.
- You resized the screenshot. Many harnesses shrink screenshots to save tokens. The Chrome DevTools MCP server's configuration guide says why this works: "image tokens scale with dimensions rather than encoded bytes" (Chrome DevTools MCP configuration, read 2026-11-26).
- The display has more device pixels than CSS pixels. In a browser, Playwright's
mouse.click(x, y)takes an "X coordinate relative to the main frame's viewport in CSS pixels" (Playwright Mouse API, read 2026-11-26). A screenshot taken at device scale on a high-density display is larger than that viewport.
How do I map a model's coordinates back to the screen?
Map coordinates back by multiplying each one by the ratio between the screen and the image the model saw.
screen_x = round(model_x * SCREEN_W / IMAGE_W)
screen_y = round(model_y * SCREEN_H / IMAGE_H)
Table: Worked example of coordinate scaling (example numbers)
| Width | Height | Point | |
|---|---|---|---|
| Screen | 1920 | 1080 | (960, 540) |
| Image sent to the model | 1280 | 720 | (640, 360) |
| Scale factor | 1.5 | 1.5 |
The model answers (640, 360) on the 1280 by 720 image; the harness clicks (960, 540) on the screen. Keep the aspect ratio when you resize, or the two axes need different factors.
For a browser agent, pick one unit and keep it. Playwright MCP's screenshot tool has a scale option where "css" gives "a screenshot sized in CSS pixels (smaller, consistent across devices)" and "device" gives "a high-resolution screenshot using device pixels"; the default is css (Playwright MCP README, read 2026-11-26). CSS-pixel screenshots line up with mouse.click with no conversion.
How does the harness send input to the desktop?
The harness sends input with a library or command that creates real mouse and keyboard events in the display server.
Table: Common ways to send computer-use actions on Linux
| Action | pyautogui (Python) | xdotool (command line) |
|---|---|---|
| Move and click | pyautogui.click(960, 540) | xdotool mousemove 960 540 click 1 |
| Type text | pyautogui.write('quarterly report') | xdotool type 'quarterly report' |
| Key combination | pyautogui.hotkey('ctrl', 's') | xdotool key ctrl+s |
| Screenshot | pyautogui.screenshot() | a separate tool, such as scrot |
Three details from the tools' own documentation matter for agents:
- xdotool's
typecommand puts a delay between keystrokes: "Delay between keystrokes. Default is 12ms" (xdotool manual, read 2026-11-26). Long text takes measurable time. - pyautogui's screenshots on Linux depend on another program: "Linux uses the
scrotcommand" (pyautogui screenshot documentation, read 2026-11-26). - With pyautogui's fail-safe on, "moving the mouse to the upper-left will raise a
pyautogui.FailSafeExceptionthat can abort your program" (pyautogui quickstart, read 2026-11-26). A model that clicks (0, 0) on purpose will trip it, so decide whether you want it on.
On a server without a monitor, run the desktop on a virtual display. Xvfb is "An X server that can run on machines with no display hardware", and by default "only screen 0 exists and has the dimensions 1280x1024x8" (Xvfb manual, read 2026-11-26). Set the size you want explicitly rather than relying on that default.
Why does screen resolution change the results?
Screen resolution changes the results because a model must find small targets in the image, and that gets harder as targets shrink or as the image is compressed.
- The OSWorld authors ran their desktop at "1920×1080" and found that "an increase in resolution directly correlates with enhanced performance" (OSWorld paper, read 2026-11-26).
- ScreenSpot-Pro tests grounding on high-resolution screens from professional applications, with "smaller target sizes". Its authors report that the best existing grounding model reached "only 18.9%", and that "strategically reducing the search area enhances accuracy": their search method reached 48.1% (ScreenSpot-Pro, arXiv 2504.07981, read 2026-11-26).
So fix one resolution per environment, keep it the same between runs, and record it with every result. If a target is small, crop the area around it and send the crop at full detail.
How does the harness know an action worked?
The harness knows an action worked only by looking again, after the screen has settled.
- Wait for the screen to settle. Playwright MCP, for example, waits after each action "for triggered work to settle", 500 ms by default (
--timeout-settle, Playwright MCP README, read 2026-11-26). On a desktop, wait for the window title or a pixel region to stop changing. - Take a new screenshot and send it with the next model call, so the model sees the result of its own action.
- Compare before and after. If nothing changed after a click, tell the model so, instead of letting it click the same point again.
- Cap the steps. A step limit and a time limit stop a loop that is stuck.
- Log every step: the screenshot, the model's raw answer, the scaled coordinates and the input sent. Most bad clicks are found by comparing the second and third.
Should the model return coordinates, element numbers or element names?
The model can return any of the three, and each needs a different harness.
Table: Three ways for a model to name its target
| Target format | What the model sees | What the harness does | Trade-off |
|---|---|---|---|
| Pixel coordinates | A plain screenshot | Scales the point and clicks it | Works on any app; most sensitive to scaling and grounding errors |
| Element number (set-of-marks) | A screenshot with a numbered box on each clickable element | Looks up the element and clicks its centre | Easier for the model; needs a list of elements to draw |
| Element reference | A text outline such as the accessibility tree | Clicks the element by reference | Precise and cheap; only works where the tree exists |
The set-of-marks idea comes from a 2023 paper that overlays "a set of marks e.g., alphanumerics, masks, boxes" on an image so a model can refer to regions by label (Set-of-Mark prompting, arXiv 2310.11441, read 2026-11-26). For browser agents, our comparison of accessibility trees and screenshots covers when each wins.
What we read for this article
- OSWorld paper (arXiv 2404.07972), read 2026-11-26
- pyautogui mouse documentation, quickstart and screenshot documentation, read 2026-11-26
- xdotool manual, read 2026-11-26
- Xvfb manual, read 2026-11-26
- Playwright Mouse API, read 2026-11-26
- Playwright MCP README, read 2026-11-26
- Chrome DevTools MCP configuration, read 2026-11-26
- ScreenSpot-Pro (arXiv 2504.07981), read 2026-11-26
- Set-of-Mark prompting (arXiv 2310.11441), read 2026-11-26
Frequently asked
Does the model control the mouse directly?
No. The model only returns text, such as an action name and a pair of coordinates. Your harness turns that into input events with a tool such as pyautogui or xdotool, or with a browser library such as Playwright.
Why does my computer-use agent click in the wrong place?
Usually because the screenshot the model saw was a different size from the screen. If you resize the image before sending it, multiply the returned coordinates by the screen size divided by the image size. High-density displays add a second scale, between CSS pixels and device pixels.
Can computer use run without a monitor?
Yes. On Linux a virtual display server such as Xvfb gives programs a screen in memory. The agent's screenshots and clicks work against that screen as they would on a real one.
How is computer use different from browser automation?
Browser automation addresses elements by selector or by the accessibility tree. Computer use addresses the screen by pixel position, so it works on any app, including ones with no automation interface, at the cost of precision and speed.