Lesson 39.5 · 5 of 5 · 5 min read · Reviewed 24 Nov 2026
Worked example: a computer use tool
By the end, you can
- Set up Claude's computer use tool at a high level.
- Know its actions and recommended environment.
Claude’s computer useComputer use: Letting a model operate a computer through screenshots, mouse and keyboard actions. tool is a client tool with a special, built-in definition. It’s offered as a beta feature, with versioned tool type names listed in the docs.
The setup
- In the request, include the computer use tool with the display size, such as 1024 x 768.
- Claude replies with
tool_useblocks containing actions: take a screenshot, move the mouse, click, type text, press a key combination, scroll and so on. - Your code performs the action in a virtual display, typically a Linux container running a desktop.
- You return a
tool_resultwith a new screenshot. - Loop until Claude stops or a limit is reached.
Companion tools are often used alongside it, such as a text editor tool and a bash tool, so Claude can edit files and run commands directly instead of through the GUI.
Start with the reference
Anthropic publishes a reference implementation with a ready-made container and agent loopAgent loop: The cycle of calling the model, running any tools it requests, returning the results and repeating until it stops.. It’s the quickest way to try computer use safely.
Bring the rest of the course
All the earlier lessons apply: turn limits and budgets (42.3), hooksHook: Code that runs automatically at a lifecycle event, such as before or after a tool call, to check, block or log it. around risky actions (44.2), confirmation steps (45.2) and logs (chapter 67).
On other providers
OpenAI and Google also ship computer-use models and tools that follow the same loop: screenshot in, action out, your code executes. Action names and coordinate conventions differ, so keep the executor behind a small interface of your own. The safety advice in 31.4 applies whichever model drives it.
Key points
- You add the computer use tool to a request with the screen size; Claude replies with actions such as screenshot, click, type and key.
- Your code performs each action in a sandboxed desktop and returns a screenshot as the tool result.
- Anthropic provides a reference implementation with a container, which is the easiest way to start.
Try computer use in the reference container
Run Anthropic's computer use reference implementation in its container, watch a short task, and inspect the actions and screenshots it exchanges.
You will have: A short run report: the task you gave, the number of actions, one action that needed a retry or check, and the limits you would add.
Steps
- Install Docker, then follow the computer use demo instructions in the anthropic-quickstarts repository to start its container.
- Keep your API key in an environment variable in your own shell and pass it to the container from there. Never paste it into a file you commit.
- Open the local web page the container serves and give it a harmless task inside the virtual desktop, such as opening a text editor and writing a short note.
- Watch the loop: note each action Claude requests (screenshot, click, type, key) and the screenshot that comes back.
- Stop the run, then write down the number of actions, any step where it had to look again, and the turn limit and confirmation steps you would add for real work.
Done when
- The container runs and the task completes inside the virtual desktop, not on your own desktop.
- Your report lists the action count and at least one verification step you observed.
- The report names at least one action you would gate behind confirmation.
Docs: Computer use tool (Claude docs) · anthropic-quickstarts (GitHub)
Finished the chapter? Take the chapter check.