superserve/desktop sandbox so Claude works an isolated Linux desktop (xfce and Google Chrome) instead of your machine. Each mouse or keyboard call is one desktop.step request, and the bash and text editor calls run through commands and files.
Setup
Run the agent loop
The script creates a desktop sandbox and sends the task with the three tools. It answers every tool call in Claude’s response, in order, and sends the results back. It stops when Claude replies without a tool call, and kills the sandbox at the end. The TypeScript sample uses top-levelawait, 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 waits for the screen to repaint and then stay still for 300 ms, for at most the step’s settle timeout, so check the frame for what you expect. When a response does not end with a screenshot, the loop attaches the latest frame to the result of the call that captured it, so Claude sees the result of its actions without another turn. A wait takes a new frame. A failed computer action drops the frame, because the screen may have changed after the capture. If the capture after an action fails, the result says so. After MAX_TURNS rounds of tool calls, the loop stops with an error if Claude still asks for tools. Set MODEL to any Claude model that supports the computer_toolset_20260801 tool.
How tool calls map to the sandbox
Clicks without a
coordinate act at the cursor. Claude spells keys as X keysyms joined with +, such as Return, ctrl+s, and alt+Tab, and press reads those names as written. The tool definition turns off zoom and hold_key with configs, and mouse actions that hold a modifier key in text return an error; add them to toDesktopActions / to_desktop_actions if your tasks need them. The desktop API lists every action the sandbox accepts.
Claude can send several tool calls in one response, and it plans the later ones on the earlier ones succeeding. So after a computer action fails, runTools / run_tools skips the rest of the computer actions in that response and answers each with Not executed: an earlier computer action in this turn failed. Every computer result echoes toolset_name: "computer", which the API requires.
Each bash call runs in a new shell as the desktop user, with /home/desktop as its home directory, so cd and exported variables do not carry over to the next call. The create command refuses a path that already exists. The files API creates files as root, so create gives the new file to desktop for the bash calls that follow.
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 Claude reads from the screen, from files, and from command output 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
desktopuser has passwordlesssudo, so Claude controls the whole sandbox. The sandbox is the boundary: do not give it secrets that the task does not need. - 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.
- Keep a person in the loop before actions with an outside effect, such as sending a message, submitting a form, or making a purchase.
Related
- Computer use: screenshots, mouse, keyboard, and the live viewer
- Commands: run shell commands in the sandbox
- Files: read and write sandbox files
- Preview URLs: access policies for the viewer port
- Network rules: limit where the sandbox can connect
- OpenAI computer use: the same desktop driven by the OpenAI
computertool