Use Computer Tools

Su Suriya Ravichandran Updated 10 Nov 2026
6 min read ·Lesson 156 of 200

When Claude Operates a Screen

Most tools Claude uses are interfaces designed for software: an API, a database, a function. Many real tasks happen in programs that have no API at all, such as a legacy desktop application, a web form with no integration, or a settings panel that must be clicked through. Computer use lets Claude work in those environments by looking at a screen and acting on it. Claude receives a screenshot, decides on an action such as moving the pointer, clicking, typing, or pressing a key, and then receives a new screenshot showing the result. It repeats this cycle until the task is done.

Computer use is powerful for exactly the same reason it is risky. An action on a screen can change data, send a message, make a purchase, or delete a file, and nothing in the environment stops it unless the application builds that protection. This lesson explains how the loop works, why it must run in an isolated environment, and how to validate every action before it is carried out.


The Loop

Computer use is a client tool in the same sense as Lessons 86–90: Claude requests an action, your code performs it, and your code returns the result. The difference is that the result is a new screenshot, and the action is a physical input on a machine.

screenshot ──► Claude decides an action ──► your code validates it ──► your code performs it
     ▲                                                                          │
     └──────────────────── new screenshot of the result ◄───────────────────────┘

The validation step in the middle is the part this lesson adds. Your code is the only thing standing between a model's decision and the machine, so it must check each action against rules that Claude cannot override.


Isolation Comes First

Before any action is validated, the environment itself must be safe to act in. The documentation recommends a dedicated, isolated environment, such as a virtual machine or container, that holds no personal accounts, no saved credentials, and no data that matters. The application should run with the least privilege the task requires, and reset the environment between tasks.

Isolation limits the damage an error can cause. Validation limits which errors can happen at all. The two work together, and neither is sufficient alone. A validator on a laptop with the owner's bank session open is not a safe design, however carefully written.


Validating Every Action

An action is a small structured request, such as a click at a position or a request to type some text. The validator below applies four kinds of rule: the action must be one the application supports, its coordinates must lie on the screen, its text and keys must be safe, and actions that look consequential must have a human's approval:

"""computer_actions.py: validate each proposed action before it touches the screen."""

ALLOWED_ACTIONS = {"screenshot", "click", "double_click", "move", "type", "key", "scroll", "wait"}
SCREEN_WIDTH, SCREEN_HEIGHT = 1280, 800
MAX_TEXT = 200
BLOCKED_KEYS = {"ctrl+alt+delete", "super", "ctrl+shift+esc"}
CONSEQUENTIAL_WORDS = {"buy", "pay", "delete", "send", "transfer", "confirm"}


def validate_action(action: dict, confirmed: bool = False) -> list[str]:
    problems: list[str] = []
    kind = action.get("action")
    if kind not in ALLOWED_ACTIONS:
        return [f"unknown action {kind!r}"]

    if kind in {"click", "double_click", "move"}:
        x, y = action.get("x"), action.get("y")
        if not (isinstance(x, int) and isinstance(y, int)):
            problems.append("coordinates must be whole numbers")
        elif not (0 <= x < SCREEN_WIDTH and 0 <= y < SCREEN_HEIGHT):
            problems.append(f"({x}, {y}) is outside the {SCREEN_WIDTH}x{SCREEN_HEIGHT} screen")

    if kind == "type":
        text = action.get("text", "")
        if len(text) > MAX_TEXT:
            problems.append(f"text longer than {MAX_TEXT} characters")
        if not confirmed and CONSEQUENTIAL_WORDS & set(text.lower().split()):
            problems.append("typing this needs human confirmation")

    if kind == "key" and action.get("key", "").lower() in BLOCKED_KEYS:
        problems.append(f"key combination {action['key']!r} is blocked")
    return problems


if __name__ == "__main__":
    proposals = [
        {"action": "click", "x": 640, "y": 400},
        {"action": "click", "x": 2000, "y": 400},
        {"action": "type", "text": "hello"},
        {"action": "key", "key": "ctrl+alt+delete"},
        {"action": "type", "text": "buy now and pay with the saved card"},
        {"action": "shutdown"},
    ]
    for number, action in enumerate(proposals, start=1):
        print(f"action {number}:", validate_action(action) or "ok")

Output:

action 1: ok
action 2: ['(2000, 400) is outside the 1280x800 screen']
action 3: ok
action 4: ["key combination 'ctrl+alt+delete' is blocked"]
action 5: ['typing this needs human confirmation']
action 6: ["unknown action 'shutdown'"]

How It Works

  1. Unknown actions are refused first. Anything outside the allowlist, such as shutdown in the last case, never reaches the machine, however plausible it sounds.
  2. Coordinates are checked against the screen. A click at x = 2000 on a 1280-pixel screen is rejected, because it would land outside the visible area or on an unexpected surface.
  3. Text and keys are limited. Long typed text is refused, which bounds how much can be entered in one step. Blocked key combinations, such as the one that opens system controls, are refused by name.
  4. Consequential text needs confirmation. The words "buy" and "pay" in the typed text trigger a requirement for human approval. The check looks at the content of the action, because the action's type alone (typing) is harmless in most contexts.
  5. Each action is judged on its own, and the function returns every problem, so a rejected action can be explained to the model in the next step.

Note: keyword checks are a backstop, not a complete safety measure. They catch obvious cases, and a determined or confused model can phrase an action in ways no list anticipates. The strongest protection is isolation and limited permissions, with human approval for anything irreversible.


Human Confirmation

For actions that cannot be undone, the application should pause and ask a person before performing them. A confirmation flow shows the proposed action, in plain language, and waits for an explicit yes. The validator's confirmed parameter represents that approval: the action goes ahead only when a person has given it, and the approval applies to that one action, not to the session as a whole.


Returning Results to Claude

After each action, the application sends the new screenshot back as the tool result, and includes any validation problem as text. Claude then decides the next action from what it sees. A rejected action should be reported clearly, with the reason, so Claude can choose a different approach, as Lesson 90 described for other tools. A rejection should not be silently replaced with a different action of the application's own choosing.


Limits of Computer Use

Computer use is slower than an API, because each step requires a screenshot and a model decision. It is also sensitive to the visual layout: a changed window, a pop-up, or a different display scale can lead to misclicks. It is best suited to tasks where no API exists, and where a human would also check the result. For tasks that have an API, the API is nearly always the better choice.

The documentation specifies the exact action names and the tool's type identifier, and these change over time, so the reference should be consulted before implementing the validator. The validator's structure, with its allowlist, bounds, and confirmations, stays the same as the reference changes.


Summary

Computer use lets Claude act through a screen, one screenshot and one action at a time. Its power comes with the need for isolation, least privilege, and a validation layer that refuses unknown, out-of-bounds, blocked, and consequential actions unless a person approves them. The application, not the model, is responsible for enforcing these rules. The next lesson returns to text, with citations that tie an answer's claims to the documents it was built from.

0 Comments

Reviewed before they appear

No comments yet.

Anthropic SDK Using Python
Anthropic SDK Intro Claude API Intro SDK Requirements Install Anthropic SDK Upgrade the SDK Create an API Key Set API Keys Use Environment Variables Import Anthropic Create a Client Send Your First Message Choose a Claude Model Set Max Tokens Read a Response Print Response Text Understand Message Blocks Use System Prompts Send User Messages Set Temperature Handle Stop Reasons Messages API Intro Create Messages Use Message Roles Send Conversation History Continue a Conversation Build a Chat Loop Reset Chat History Use Multiple Turns Inspect Message IDs Read Usage Data Write Clear Prompts Set a System Prompt Add Context to Prompts Use Prompt Templates Add Examples to Prompts Request JSON Output Use XML Tags Control Response Length Improve Prompt Quality Avoid Prompt Injection Read Text Blocks Read Content Blocks Check Stop Reasons Count Input Tokens Count Output Tokens Count Tokens Before Sending Limit Output Tokens Use Stop Sequences Read Request IDs Parse API Responses Streaming Intro Stream Text Output Use Stream Events Use Stream Helpers Get Final Messages Stream Async Responses Handle Stream Errors Build a Live Chat Stream Long Responses Close Streams Safely Build a Chatbot Keep Chat History Manage Chat Sessions Add Chat Memory Build a CLI Chatbot Build a Web Chatbot Use Flask with Claude Use FastAPI with Claude Return JSON from an API Add Chat Error Messages Async SDK Intro Create an Async Client Send Async Messages Use asyncio Run Parallel Requests Stream Async Text Handle Async Errors Set Async Timeouts Close Async Clients Choose Sync or Async Tool Use Intro Define a Tool Create Tool Schemas Send Tools to Claude Read Tool Calls Run Python Tools Return Tool Results Continue After Tool Use Control Tool Choice Handle Tool Errors Use the beta_tool Decorator Create a Tool Runner Add Tool Docstrings Validate Tool Inputs Use Multiple Tools Limit Tool Calls Log Tool Activity Build a Weather Tool Build a Search Tool Build a Calculator Tool Structured Output Intro Request JSON Data Validate JSON Output Use Pydantic Models Handle Invalid JSON Extract Fields from Text Generate Typed Data Use Image URLs Send Base64 Images Read PDFs with Claude Use Output Schemas Build Data Extraction Test Structured Responses Send Image Inputs Upload Files Use File IDs Process Text Files Summarize Documents Extract Table Data Handle File Errors Read Cache Usage Reduce Repeated Input Costs Debug Cache Misses Prompt Caching Intro Enable Prompt Caching Cache System Prompts Cache Long Context Test Cache Performance Use Cache Breakpoints Cache Best Practices Message Batches Intro Create a Message Batch Set Batch IDs Check Batch Status List Message Batches Get Batch Results Process Batch Outputs Handle Failed Batch Items Use Batches for Bulk Tasks Compare Batches and Requests Handle API Errors Handle Rate Limits Retry Failed Requests Set Request Timeouts Handle Network Errors Use Exponential Backoff Build Reliable API Calls Use Extended Thinking Log API Errors Track Request IDs Paginate API Results Set Thinking Budgets Read Thinking Blocks Use Tool Search Use Web Search Tools Use Computer Tools Use Citations Use Token Counting Read Raw Responses Set Custom Headers Use Claude on AWS Bedrock Use Claude on Vertex AI Use Claude on Microsoft Foundry Configure Cloud Credentials Choose a Cloud Provider Compare API Integrations Configure Provider Clients Handle Cloud Errors Use Cloud SDK Extras Deploy Cloud Apps Protect API Keys Use a .env File Ignore Secrets in Git Validate User Input Reduce Prompt Injection Limit Tool Permissions Avoid Unsafe Tool Calls Sanitize Tool Results Set Usage Limits Review Security Logs Test SDK Functions Mock API Responses Test Error Handling Test Streaming Code Measure Token Usage Track API Costs Configure Logging Deploy with Docker Deploy a FastAPI App Monitor Production Apps Build a Claude Chatbot Build a Text Summarizer Build a Code Explainer Build a JSON Extractor Build a PDF Assistant Build a Streaming Chat App Build a Tool-Calling Agent Build a Batch Processor Build a Research Assistant Build a Claude API Dashboard
Ask about this post
AI Ask about this post

Ask questions about Use Computer Tools and get answers drawn from it.

Signed-in readers only.