computer tool in the OpenAI Responses API lets a model operate a graphical desktop: it reads a screenshot, returns mouse and keyboard actions, and your code runs them and sends back the next screenshot. Point that loop at a superserve/desktop sandbox so the model works an isolated Linux desktop (xfce and Google Chrome) instead of your machine. Each model turn is one desktop.step request: the sandbox runs the actions and returns the screen after them.
Setup
Run the agent loop
The script creates a desktop sandbox, sends the task with thecomputer tool, and then answers each computer_call with a screenshot taken after its actions ran. It stops when the model replies with text, and kills the sandbox at the end.
The TypeScript sample uses top-level await, so it must run as an ES module: save it as agent.mts (or set "type": "module" in package.json) and run it with npx tsx agent.mts.
waitForChange / wait_for_change with quietMs / quiet_ms returns the first frame after the screen repainted and then stayed still for 300 ms, so the model sees the result of its actions instead of a frame from the middle of a repaint. Set MODEL to any model your OpenAI project can use with the computer tool.
How actions map to the desktop
The sandbox reads key names such as
ENTER, CTRL, ALT, TAB, and F2 without regard to case. KEYS renames the few that the model spells differently. Clicks with the back or forward button and actions that hold modifier keys throw an error; add them to toDesktopActions / to_desktop_actions if your tasks need them. The desktop API lists every action the sandbox accepts.
Watch it live
getStreamUrl / get_stream_url returns a browser URL for the desktop viewer. The script creates the sandbox with the private preview policy, so that URL carries a signed credential that expires after 60 seconds. On first open, the viewer moves the credential into a cookie and drops it from the address bar. Until then, treat the URL as a secret, and mint a fresh one for each viewer. viewOnly / view_only stops that viewer from sending input, but anyone who has the URL can open it without the flag, so keep the policy private when the screen shows anything sensitive.
Safety
- Everything the model reads from the screen is untrusted input: web pages, files, and dialogs can carry instructions aimed at the model. Keep credentials and personal data out of the desktop.
- The model calls run in your code, not in the sandbox, so the sandbox needs to reach only the sites the task uses. Restrict everything else with network rules.
- A
computer_callcan carrypending_safety_checks. The script stops on them. To continue after a person reviews the checks, send them back asacknowledged_safety_checkson the nextcomputer_call_output. - Keep a person in the loop before actions with an outside effect, such as sending a message, submitting a form, or making a purchase.
Use computer-use-preview
The loop above targets thecomputer tool. An integration built on the older computer-use-preview model changes the request as follows:
actionsOf / actions_of already reads both shapes, so only the request parameters change.
Related
- Computer use: screenshots, mouse, keyboard, and the live viewer
- Preview URLs: access policies for the viewer port
- Network rules: limit where the sandbox can connect
- MCP Sandboxes: the same desktop as an MCP tool