Computer use
A desktop in the workspace that your product's agents drive with screenshots, clicks and keystrokes: model toolsets, agent tools, the CLI and MCP.
Install once with npm i -g shardflux, then use the shard command. If npm reports EACCES or EPERM, follow the user-directory install and use "$HOME/.local/bin/shard".
What computer use gives an agent
A workspace with computer use on has a Linux desktop, 1280x800 by default, that the agent in your product operates like a person: it takes screenshots, moves the pointer, clicks, types and presses keys. Use it for software that has no API: web apps behind a login, desktop applications, anything an agent should see before it acts.
- On demand. Switch computer use on for a workspace or for every workspace of a template. The platform starts the desktop on the first computer call, in about 0.35 s, and keeps it running with the workspace.
- Fast. A click and the screenshot after it take about 20 ms in the workspace's region (p50, 1280x800 PNG). A batch of actions runs in one request.
- Part of the workspace. Commands, files and the desktop share one machine:
execofchromium https://example.com &opens the browser on the desktop. Suspend and resume keep its windows. - Watchable. A private link shows the desktop live in a browser, view only or interactive.
- Yours to take over. A person drives the desktop with their own mouse and keyboard while the agent waits for them.
| Client | Version | Switch | Actions |
|---|---|---|---|
| TypeScript SDK | @shardflux/sdk (0.15.0+) |
open({ computerUse }), workspace.setComputerUse() |
workspace.computer.act(), computerToolset() |
| Python SDK | shardflux (0.11.0+) |
open(computer_use=), ws.set_computer_use() |
ws.computer.act(), computer_toolset() |
| CLI | @shardflux/cli (0.10.0+) |
shard ws computer enable, shard ws open --computer-use on |
shard ws computer click|type|key|... |
| Agent tools and MCP server | @shardflux/sdk (0.15.0+), @shardflux/mcp (0.9.0+) |
workspace_set_computer_use (MCP) |
computer, computer_batch |
| HTTP | /v1 |
PUT /v1/workspaces/{id}/computer-use |
POST <cell_endpoint>/v1/workspaces/{id}/computer/actions |
The desktop comes with the python-node-browser template (version 15 and later) and every template built on it.
Switch it on
import { Shardflux } from '@shardflux/sdk';
const cloud = new Shardflux();
const ws = await cloud.workspaces.open({ key: 'agent/42', template: 'python-node-browser', computerUse: true });computerUse: true(Pythoncomputer_use=True) switches it on for a new or existing workspace;falseswitches it off;null(None) follows the template.workspace.setComputerUse()changes it later.cloud.templates.setComputerUse(slug, true)switches it on for every workspace of one of your templates; a workspace's own setting wins.- In the dashboard, the workspace's Overview has a Computer use row with the switch and Watch desktop.
workspace.computerUsereads{ enabled, workspace, template, available }.
While computer use is on, the workspace's tool tokens carry the computer tool. An API key needs the computer tool
permission, which keys created with every tool have, including the keys shard setup creates (CLI 0.15.1+).
With Claude's computer toolset
computerToolset() answers Claude's computer toolset: all of a model turn's computer calls run as one batch, and each
answer comes back as the tool_result Claude expects.
import Anthropic from '@anthropic-ai/sdk';
import { computerToolset } from '@shardflux/sdk';
const anthropic = new Anthropic();
const computer = computerToolset(ws);
const messages = [{ role: 'user', content: 'Open example.com in Chromium and tell me the page title.' }];
for (;;) {
const msg = await anthropic.messages.create({ model: 'claude-opus-5-5', max_tokens: 4096, tools: [computer.definition], messages });
messages.push({ role: 'assistant', content: msg.content });
if (msg.stop_reason !== 'tool_use') break;
messages.push({ role: 'user', content: await computer.run(msg.content) });
}from anthropic import Anthropic
from shardflux import computer_toolset
client = Anthropic()
computer = computer_toolset(ws)
messages = [{"role": "user", "content": "Open example.com in Chromium and tell me the page title."}]
while True:
msg = client.messages.create(
model="claude-opus-5-5", max_tokens=4096, tools=[computer.definition], messages=messages
)
messages.append({"role": "assistant", "content": msg.content})
if msg.stop_reason != "tool_use":
break
messages.append({"role": "user", "content": computer.run(msg.content)})Every tool_result echoes toolset_name: "computer". A turn that does not end with a screenshot gets one after its
last action, on the last result.
Agent tools for any model
workspaceTools() (Python workspace_tools()) includes two computer tools while the workspace's computer use is on:
| Tool | Takes | Answers |
|---|---|---|
computer |
One action with its parameters |
ok, output, error, cursor, display, and screenshot (a screenshot after an input action, the image of screenshot and zoom) |
computer_batch |
actions: 1-50 actions |
ok, results (per action: ok, skipped, output, error, took_ms, a zoom's image), cursor, display, screenshot |
Both take screenshot: false to skip the screenshot, settle_ms (the wait before it when the screen may change,
default 250) and format: "jpeg" with quality for smaller images. Images are base64 in data_base64 with their
mime_type, width and height.
Drive it from code
const shot = await ws.computer.screenshot(); // { format: 'png', width: 1280, height: 800, data }
const r = await ws.computer.act(
[
{ action: 'left_click', coordinate: [640, 400] },
{ action: 'type', text: 'hello' },
{ action: 'key', text: 'Return' },
],
{ screenshot: true },
);
// r.results: one per action; r.screenshot after the last one; r.cursor; r.displayact(actions, { screenshot, settleMs, format, quality })runs the actions in order. The first failure stops the batch; the actions after it come backskipped.status(),start({ width, height })(640x480 to 2560x1600) andstop()manage the desktop directly.
From the command line
shard ws open acme/demo --template python-node-browser --computer-use on
shard ws exec-start acme/demo -- chromium https://example.com
shard ws computer screenshot acme/demo --out desktop.png
shard ws computer click acme/demo 640 400
shard ws computer type acme/demo "hello" --screenshot after.png
shard ws computer key acme/demo ctrl+s| Command | Action |
|---|---|
click <ws> [x y] [--button left|right|middle] [--count 2|3] [--mods keys] |
A click, double or triple click at a point or at the pointer |
type <ws> <text|-> |
Types text (Unicode; - reads standard input) |
key <ws> <keys> [--repeat n] |
Keys and combinations: Return, ctrl+s, alt+Tab, several separated by spaces |
scroll <ws> up|down|left|right [x y] [--amount n] |
Wheel clicks (default 3) |
move <ws> <x> <y>, drag <ws> <x1> <y1> <x2> <y2> |
Moves the pointer; drags with the left button |
mouse-down <ws>, mouse-up <ws>, hold-key <ws> <keys> <seconds> |
Holds the left button or keys |
zoom <ws> <x0> <y0> <x1> <y1> [--out F] |
Saves an enlarged view of a region |
cursor <ws>, wait <ws> <seconds> |
Prints the pointer position; waits |
act <ws> <json|-> |
Any of these in one batch: a JSON array of actions |
status, start [--width --height], stop |
The desktop itself |
Every input command takes --screenshot F (a screenshot after it), --settle MS and --format jpeg --quality N.
From MCP
The Shardflux MCP server lists, for API keys with the computer permission:
computerandcomputer_batch, with their images as MCP image content;workspace_computer_desktop: the desktop's status, a start at a chosen screen size, or a stop;workspace_computer_stream: a link to watch the desktop, or use it withinteractive: true;workspace_set_computer_use(state:on,offorinherit) for every key.
Watch it live
const { url, expiresAt } = await ws.computer.stream(); // view only
const live = await ws.computer.stream({ interactive: true, ttlSeconds: 3600 });The link opens the desktop in any browser until it expires (24 hours by default): view only, or with the mouse and
keyboard when interactive. Share it like a password. stopStream() (Python stop_stream(), CLI
shard ws computer stream --stop) ends every view. The viewer is served through the workspace's
inbound ports. An open viewer keeps the workspace awake through its WebSocket; no extra keepalive is needed.
Stream the screen to your own view
Draw the desktop in your own app, desktop or web, with nothing to expose or embed: frames() streams the screen as
images, one each time it changes.
const frames = await ws.computer.frames({ maxFps: 5 }); // JPEG by default; format: 'png', quality: 1-100
for await (const f of frames) {
view.src = URL.createObjectURL(new Blob([f.data], { type: `image/${f.format}` })); // seq, width, height, capturedAt
}
// frames.close() when the view closeswith ws.computer.frames(max_fps=5) as frames:
for f in frames:
show(f.data, f.format)Frames arrive up to maxFps (1-10, default 5) a second while the screen changes and not at all while it is still,
so a still desktop sends no data. A slow reader gets the newest screen, never a backlog. The workspace stays awake
while the stream is open, so close it when the view closes. Over the cell API it is the WebSocket GET /computer/frames
(reference).
Embed the viewer
Watch the agent inside your own web app. Choose the HTTPS origins that may host the iframe:
const viewer = await ws.computer.stream({
interactive: false,
ttlSeconds: 3600,
embed: { origins: ['https://app.example.com'] },
});
document.querySelector<HTMLIFrameElement>('#agent-view')!.src = viewer.url;<iframe id="agent-view" title="Watch the agent" style="width:100%;height:600px;border:0"></iframe>viewer = ws.computer.stream(embed={"origins": ["https://app.example.com"]})shard ws computer stream customer-42/main --embed-origin https://app.example.comMCP's workspace_computer_stream accepts embed_origins: ["https://app.example.com"].
For mouse and keyboard access, set interactive: true with the same origin allowlist. An open viewer keeps
the workspace awake for the connection's lifetime. The browser session is partitioned by the top-level site.
Take over
Let a person step in when the agent needs one: a sign-in, a confirmation, a quick fix in an app.
GET <cell_endpoint>/v1/workspaces/{id}/computer/vnc is the desktop as VNC (RFB) in a WebSocket with subprotocol
binary, the stream noVNC's RFB client speaks. With control=true the person takes over for as long as the socket is
open; without it the stream is view only.
const { url, token } = await ws.cell().computer.vncUrl({ control: true }); // send the token as Authorization: Bearerwith ws.cell().computer_vnc(control=True) as vnc: # RFB bytes: vnc.receive(), vnc.send_bytes()
...While a person has control, the agent's input actions wait for them, up to 25 seconds per call (python-node-browser
25+). An action that waited does not run: it answers the action error taken_over with a fresh screenshot, so the
agent looks at the screen the person left before it acts again. Screenshots and zooms never wait. TypeScript 0.32.5+,
Python 0.28.3+.
Actions
Keystrokes reach any app on the desktop, including a terminal, so apply your exec policy to type and key.
| Action | Parameters |
|---|---|
screenshot |
|
zoom |
region: [x0, y0, x1, y1], answered with that region enlarged |
left_click, right_click, middle_click, double_click, triple_click |
coordinate (default: at the pointer), text: modifiers held, e.g. shift |
left_click_drag |
start_coordinate, coordinate, text (modifiers) |
mouse_move |
coordinate |
left_mouse_down, left_mouse_up |
|
cursor_position |
Answered with X=…, Y=… |
scroll |
scroll_direction (up, down, left, right), scroll_amount, coordinate, text (modifiers) |
type |
text |
key |
text: keys such as Return, ctrl+s, alt+Tab, several separated by spaces; repeat |
hold_key |
text, duration (seconds) |
wait |
duration (seconds) |
Coordinates are screen pixels from the top-left of a screenshot. Key names follow X keysyms (Return, Escape,
Page_Down, F5), and the common aliases (enter, esc, cmd, ArrowUp) work too.
Your own desktop
A template built on python-node-browser 15 or later has the desktop. Its session (window manager and panel) is the
script /etc/shardflux/desktop/session: replace it in your template to start another window manager or your
application.
Reuse viewer links and apply action policy
TypeScript 0.16.0+ and Python 0.12.0+ reuse a viewer link of the same kind (interactive or view only)
while more than 60 seconds remain. stream({ fresh: true }) / stream(fresh=True) mints a new link;
stopStream() / stop_stream() clears the cache. CLI 0.11.0+ uses --fresh, and MCP 0.10.0+ uses fresh: true.
act() and computer_batch return a final screenshot or zoom image once, without another trailing screenshot.
Set computerToolset(ws, { beforeAction }) or workspaceTools(ws, { computer: { beforeAction } }) to check each
action immediately before it runs. Return false, a refusal string, or throw to answer that action with an error
and skip the rest; the hook may be async. Python uses computer_toolset(ws, before_action=policy) or
workspace_tools(ws, computer={"before_action": policy}), with False, a refusal string, or an exception.