Documentation menu

Computer use

computerTool lets the model look at a screen and use the mouse and keyboard. You supply a Computer driver for the screen it controls; Yada scales screenshots, maps coordinates, asks for approval and keeps actions from repeating after a restart. Any provider with vision can use it.

In the terminal agent, yada --computer browser or --computer docker sets this up for you; see the terminal guide.

Run the driver against a dedicated virtual machine, container or browser profile, never a machine with the user’s sessions or credentials. Prefer typed tools, connectors and MCP servers whenever they can do the job; the screen is the slowest and least reliable route.

import { computerSystem, computerTool, run } from "@edgaralochi/yada";

const result = await run({
  provider,
  tools: [
    computerTool({
      computer: myComputer,
      authorize: (identity) => canUseComputer(identity),
      mode: "ask",
    }),
  ],
  identity,
  input: "Download last month's invoice from the billing portal.",
  system: `${computerSystem}\n\nYou help with billing tasks.`,
  signal: AbortSignal.timeout(600_000),
  limits: { maxRounds: 150, maxToolCalls: 300, maxDurationMs: 600_000 },
});

Screen tasks take many steps. Raise maxRounds and maxToolCalls and set maxDurationMs for runs that use the computer.

Modes

Mode Screenshots, zoom, cursor, wait Clicks, typing, keys, scrolling
observe yes not offered to the model
ask yes each action asks for approval (default)
auto yes yes

In ask mode each mutating action asks through the run’s elicitation channel, the same one MCP elicitation uses, with an empty form and one of these messages:

Tool Message
computerTool Allow the computer action {...}?
computerTool, as a batch Allow the computer actions [...]?
browserTool Allow the browser action {...}?

Under the worker the run suspends with awaiting_approval and continues once the user answers; a plain run() needs an executeWrite with an ask. Errors reach the model as JSON with an error code: denied when the user declines or the run cannot ask, refused when the driver refuses the action (an app without permission, an unknown key, a blocked domain), and invalid_arguments for a bad call. A denied or invalid_arguments error performs nothing; in a batch, a later error leaves the earlier actions done.

Actions

The model calls one tool, computer by default, with an action and its fields:

Action Fields
screenshot  
zoom region: [x0, y0, x1, y1]
cursor_position  
wait duration (seconds, up to 60)
left_click, right_click, middle_click, double_click, triple_click optional coordinate: [x, y], text (modifier keys held)
left_click_drag start_coordinate, coordinate
mouse_move coordinate
left_mouse_down, left_mouse_up  
scroll scroll_direction, scroll_amount, optional coordinate, text
type text
key text (for example ctrl+s), optional repeat
hold_key text, duration

screenshot and zoom return an image; cursor_position returns [x, y]; every other action returns OK, so the model takes a screenshot to see the result. zoom and cursor_position are offered only when the driver implements them.

Every driver accepts the same key names, case-insensitive and joined with +: modifiers (ctrl, alt or option, shift, cmd, super or meta), Enter or Return, Escape, BackSpace, Delete, Tab, space, Insert, Home, End, PageUp, PageDown, the arrows Up, Down, Left and Right, F1 to F12, letters, digits, punctuation by character or xdotool name (minus, slash), and plus for +. Any other key returns a refused error.

Providers

With Anthropic Claude 5 models (claude-opus-5*, claude-sonnet-5*, claude-haiku-5*, Fable and Mythos 5), the adapter sends the tool as Anthropic’s native computer_toolset_20260801 instead of a function tool, disables the members the tool does not offer (for example every mutating action in observe mode), maps each member call back to your tool with its action, and echoes toolset_name on the results. Several member calls in one response run in order as described below. The native toolset allows wait and hold_key up to 300 seconds; Yada accepts up to 60 and returns invalid_arguments above that.

With OpenAI gpt-6* models on the Responses API (provider: "openai"), the adapter declares OpenAI’s native computer tool. Each computer_call becomes one call to your tool with an actions batch: the whole batch is checked first, so a bad action or coordinate runs none of it; the actions then run in order and stop at the first error, which names the action as actions[i]. A screenshot is always taken at the end and returned as the computer_call_output, and any error text is sent to the model as a user message next to it. In ask mode a batch with any mutating action is approved once; a batch that only observes runs without asking. When a call carries pending_safety_checks, Yada asks the user even in auto mode, with the checks’ messages; only an approved batch acknowledges them. OpenAI key names (CTRL, ENTER) are converted to the key names drivers accept.

Older Claude and OpenAI models, Gemini, DeepSeek, local models and LangChain get the portable function tool, which works with any model that has vision. Gemini’s own computer use runs through Google’s separate Interactions API, which the Gemini adapter does not use.

Native member calls are replayed as they were only to a model that has the same toolset; after a switch to another model they are sent as ordinary calls to your tool. Claude 5 models bind their thinking blocks to an unchanged history, and Yada’s context compaction replaces older screenshots with [image omitted]. Screenshot-heavy runs reach maxContextChars sooner (each image counts as 6,400 characters), so raise it for computer runs on Claude, for example limits: { maxContextChars: 2_000_000 }, to keep compaction rare.

Coordinates and scaling

Screenshots are sent at the screen’s size, scaled down so the long edge is at most maxLongEdge (default 1,280 pixels). The model’s coordinates are pixels in that screenshot, and Yada converts them to screen pixels before calling the driver. A coordinate outside the screenshot returns an invalid_arguments error. zoom regions use screenshot pixels too, and the zoomed image is scaled the same way.

Ordering and recovery

computerTool is marked stateful. Its calls never run in parallel with other tools, and when one fails, the later calls to it in the same model response return not_executed without running. Yada records each stateful call in the checkpoint before it starts; if the process stops before the result is saved, the resumed run returns interrupted for that call instead of repeating it, and the model checks the screen again. Custom read tools that change external state can set stateful: true in readTool for the same behaviour.

Browser driver

playwrightComputer({ page, allowedDomains }) drives a Playwright page you create, so install playwright (or @playwright/test) yourself; Yada does not import it.

import { chromium } from "playwright";
import { computerTool, playwrightComputer } from "@edgaralochi/yada";

const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1280, height: 720 } });
const computer = await playwrightComputer({
  page,
  allowedDomains: ["billing.example.com"],
});
await page.goto("https://billing.example.com/");
const tool = computerTool({ computer, authorize, mode: "ask" });
  • Give the page a fixed viewport whose long edge is at most maxLongEdge; the driver does not resize screenshots and fails with a message naming the size it needs.
  • The page has no address bar. Open the start page with page.goto before the run; the model moves on through links and forms.
  • allowedDomains aborts page navigations to any other host (a domain also allows its subdomains; [] blocks every web navigation) and to any scheme except http, https and about:. Images, scripts and other subresources still load. Leave it out only for pages you fully trust.
  • Use a fresh browser context without the user’s cookies, and one page per run.

examples/computer.ts fills in a form on a local page with your configured provider: node --env-file=.env --import tsx examples/computer.ts.

Browser tool

browserTool gives the model a browser it reads through the page’s structure instead of pixels: read_page and find return elements with refs such as button "Buy" [ref_5], and clicks, scroll_to and form_input take { type: "ref", ref } or { type: "coordinate", x, y }. It is usually faster and more reliable than computerTool for web tasks. playwrightBrowser({ context, allowedDomains }) drives a Playwright browser context with tabs (new_tab, list_tabs, switch_tab, close_tab).

import { chromium } from "playwright";
import { browserTool, playwrightBrowser } from "@edgaralochi/yada";

const context = await (
  await chromium.launch()
).newContext({
  viewport: { width: 1280, height: 800 },
});
const browser = await playwrightBrowser({
  context,
  allowedDomains: ["billing.example.com"],
});
const tool = browserTool({ browser, authorize, mode: "ask" });
  • wait and hold_key take up to 30 seconds. Modes work as for computerTool: observe offers screenshot, zoom, wait, read_page, find, get_page_text and list_tabs; ask asks before every other member with Allow the browser action {...}?.
  • navigate accepts only http and https URLs (a URL without a scheme, such as localhost:3000, gets https://) and, with allowedDomains, only those hosts. Navigations started by the page are blocked the same way, and a tab that a redirect takes to another host is reset to about:blank with a refused error. A stale ref and other driver errors are refused errors too.
  • Refs are element handles held by the driver, outside the page, so neither the page’s markup nor its scripts can point a ref at another element. A ref from an earlier page or a removed element returns a refused error. Page text that starts like a browser_state block is prefixed with a space, so a page cannot forge tab state.
  • With Claude 5 models and Claude Opus 4.8, the adapter sends Anthropic’s native browser_toolset_20260801, maps each member call back to your tool and returns tab changes as browser_state blocks. Other providers get the portable function tool. Script, upload, console and network members are not offered.
  • Screenshots are not resized: keep the viewport’s long edge at most 1,280 pixels.

Desktop sandbox

deploy/computer/Dockerfile builds a Debian desktop (Xvfb, Openbox, Firefox) that dockerComputer drives with xdotool through docker exec:

docker build -t yada-computer deploy/computer

The screen is 1280×800 by default (-e WIDTH=… -e HEIGHT=…) and Firefox opens START_URL. Port 6080 serves noVNC, without a password unless you pass -e VNC_PASSWORD=…, so publish it only on localhost (-p 127.0.0.1:6080:6080) and open http://127.0.0.1:6080/vnc.html to watch or take over.

In the worker, give each run its own container. Profile tools can be a function that runs whenever the worker picks the run up, so a run that resumes after an approval reattaches to its container by name:

import { createHash } from "node:crypto";
import {
  computerSystem,
  computerTool,
  startDockerComputer,
} from "@edgaralochi/yada";

const profiles = {
  desktop: {
    provider,
    system: computerSystem,
    tools: async ({ identity, conversationId, runId }) => [
      computerTool({
        computer: await startDockerComputer({
          name: `yada-${createHash("sha256")
            .update(JSON.stringify([identity.tenantId, conversationId, runId]))
            .digest("hex")
            .slice(0, 24)}`,
          image: "yada-computer",
          args: ["--memory", "2g", "--cpus", "2"],
          signal: AbortSignal.timeout(30_000),
        }),
        authorize,
        mode: "ask",
      }),
    ],
  },
};

startDockerComputer starts a stopped container, creates a missing one with docker run -d --name {name} {args} {image} and waits until the display answers; a container it created that never becomes ready is removed. Otherwise Yada does not remove containers: delete them with docker rm -f when the run ends, and on a schedule for runs left waiting for an approval. For a display you run yourself, xdotoolComputer({ display }) runs xdotool and ImageMagick’s convert locally.

macOS desktop

macosComputer({ apps, hideOthers, onEscape }) drives the Mac it runs on with screencapture, sips and JavaScript for Automation, without extra packages. Use it only on a Mac set aside for the agent: it moves the real pointer and types into real apps.

import { computerTool, macosComputer } from "@edgaralochi/yada";

const controller = new AbortController();
const computer = macosComputer({
  apps: { Calculator: "full", Preview: "click", Safari: "view" },
  hideOthers: true,
  onEscape: () => controller.abort(),
});
const tool = computerTool({ computer, authorize, mode: "ask" });
// run({ ..., tools: [tool], signal: controller.signal }), then computer.close()
  • apps names apps as the Dock shows them, each with a tier: view (visible on screenshots only), click (mouse actions too) or full (typing and keys as well). A mouse action checks the app owning the window under the target point; typing and keys check the frontmost app. Anything else, including the Dock and menu bar extras, returns a refused error that asks the model to get the user’s permission.
  • hideOthers hides every app not in apps before the first action, so screenshots show only what the model may see. Without it, screenshots show every app on screen, whatever its tier.
  • onEscape is called whenever the Escape key is pressed on the physical keyboard; abort the run there. close() stops listening.
  • Grant the process that runs Node (Terminal, iTerm or your service) Screen Recording and Accessibility in System Settings → Privacy & Security. Coordinates are in points of the main display; Retina screenshots are scaled to the size computerTool asks for.
  • Drivers you write, for computerTool or browserTool, can throw ActionRefused the same way to refuse an action with a message the model sees.

Service and widget

Pass one createScreenStore() to createWorker and createHandler, as with the event bus. The worker keeps the latest screenshot of each run’s computer or browser tool there (zoomed images excluded) until the run ends, and GET /v1/conversations/{conversationId}/runs/{runId}/screen returns it as an image (404 when there is none). Screenshots stay in memory only: run events and the database never hold them, createScreenStore(max) keeps the max most recent runs (256 by default), and a restart empties it. Worker and handler must share the process, or a store you implement over shared memory such as Redis.

import {
  createEventBus,
  createHandler,
  createScreenStore,
  createWorker,
} from "@edgaralochi/yada";

const bus = createEventBus();
const screens = createScreenStore();
const worker = createWorker({ storage, profiles, bus, screens });
const handler = createHandler({ storage, bus, screens /* , ... */ });

BrowserClient.getScreen(conversationId, runId) returns the screenshot as a Blob, or undefined; poll it while the run is active to show a live view. When the widget shows a pending computer or browser approval, it loads the screenshot into the approval card and circles each coordinate the action targets (part approval-screen, label approvalScreen, color --yada-target-color). Allow blob: images in your Content Security Policy (img-src 'self' blob:).

To take over, open the sandbox’s noVNC page (/vnc.html on port 6080, served only to the user who owns the run, for example through your authenticated proxy). Do the step yourself, send a steering message describing what you did, then decline the pending action. The model receives the denial and your message together and continues from the new screen.

Drivers

A Computer works in screen pixels:

import type { Computer } from "@edgaralochi/yada";

const myComputer: Computer = {
  size: async (signal) => ({ width: 1920, height: 1080 }),
  screenshot: async ({ width, height }, signal) => ({
    type: "image",
    mimeType: "image/png",
    data: await captureScaled(width, height, signal),
  }),
  act: async (action, signal) => {
    /* perform the click, key press or scroll at screen coordinates */
  },
  zoom: async ([x0, y0, x1, y1], { width, height }, signal) => ({
    type: "image",
    mimeType: "image/png",
    data: await captureRegion(x0, y0, x1, y1, width, height, signal),
  }),
  cursorPosition: async (signal) => [0, 0],
};

screenshot must return an image of the requested size; act receives the action with coordinates already in screen pixels. Honour signal and keep one run per driver at a time. createFakeComputer({ width, height, screens }) records actions and requested screenshot sizes for tests and evals.

Safety

  • Everything on the screen is untrusted. computerSystem tells the model never to follow instructions shown on it and to ask before purchases, messages, account creation, terms and personal data; add your own rules after it.
  • Keep secrets out of the environment the model can see. Do not ask the model to type passwords or card numbers.
  • authorize decides which identities see the tool, as with any tool. Start with ask and move to auto only for environments where every reachable action is acceptable.