Clients for the hosted API#
Two small clients drive the hosted API without writing HTTP by hand:
computerworld-cloud for Python (standard library only, Python 3.9 or later) in
python/, and computerworld-cloud for JavaScript (one ES
module, no dependencies, Node 18 or later and browsers, with TypeScript declarations) at
the root of the same public repository. An API key acts in the organization it was made in (the hosted API § Organizations), so a team's key reaches the team's environments. They have the same shape: a Client holding an API key,
an Environment handle for a running environment (the engine's World) and an Agent
handle for an external agent in it (the engine's Environment, one actor's session, not the
hosted environment), with methods named after
the engine's own, so code moves between a local world and a hosted environment with few changes. Python uses snake_case, JavaScript camelCase.
Install#
The Python client is computerworld-cloud on PyPI. Both are written in their public repository,
ComputaCo/computerworld, MIT-licensed, and the JavaScript one installs
from there.
# Python
pip install computerworld-cloud
# JavaScript, in a Node project
npm install github:ComputaCo/computerworld
// JavaScript, from a URL (browsers, Deno); pin a tag or commit for anything lasting
import { Client } from 'https://cdn.jsdelivr.net/gh/ComputaCo/computerworld@main/computerworld-cloud.mjs';
The JavaScript client is one file, so copying computerworld-cloud.mjs (and
computerworld-cloud.d.mts for types) into a project works too.
A first run#
Both read COMPUTERWORLD_API_KEY and COMPUTERWORLD_API_BASE when no key or base URL is
passed. A key works only with the API of the site where it was made, so set the base to that
site's API; the address below is the API of the site you are reading. The base may be given
with or without /v1; with none, the clients use the production API at computaco.ai. A
refused key's error names the API it went to.
export COMPUTERWORLD_API_KEY=cw_live_...
export COMPUTERWORLD_API_BASE=https://computaco.ai/v1
from computerworld_cloud import Client
client = Client()
with client.create_environment("agent-desktop", seed=1) as env: # deleted on exit
agent = env.agent()
agent.click(interaction="shell:launch:editor") # find in the scene, click the centre
agent.click(role="textbox") # the editor's text (GTK 4 gives it no name)
agent.type_text("Hello")
agent.render().save("screen.png")
fork = env.fork()
run = fork.run("agent-desktop/legal-engagement", seed=1)
print(run["verification"]["passed"])
fork.delete()
import { Client } from 'computerworld-cloud';
const client = new Client();
const env = await client.createEnvironment('agent-desktop', { seed: 1 });
try {
const agent = await env.agent();
await agent.click({ interaction: 'shell:launch:editor' });
await agent.click({ role: 'textbox' }); // the editor's text (GTK 4 gives it no name)
await agent.typeText('Hello');
const { bytes } = await agent.render(); // PNG
const fork = await env.fork();
const run = await fork.run('agent-desktop/legal-engagement', { seed: 1 });
console.log(run.verification.passed);
await fork.delete();
} finally {
await env.delete();
}
Local and hosted, side by side#
| Local engine | Python client | JavaScript client |
|---|---|---|
World(definition, seed) | client.create_environment(template | definition=, seed=) | client.createEnvironment(template, { definition, seed }) |
world.environment(config) | env.agent(config) | env.agent(config) |
snapshot, restore, fork | the same; a snapshot is kept by the API and named by id | the same |
| (hosted only) the family's history | env.history(), env.snapshot_frame(snapshot, machine) → PNG bytes | env.history(), env.snapshotFrame(snapshot, machine) → { bytes, … } |
export_snapshot / import_snapshot | export_snapshot() / client.import_environment(bundle) (the bundle's snapshot is bytes) | exportSnapshot() / client.importEnvironment(bundle) (snapshot a Uint8Array) |
state_hash, inspect, definition, trajectory, reset | the same | stateHash, inspect, … |
add_computer, remove_computer | the same | addComputer, removeComputer |
instantiate, stage, project, verify | client.instantiate, env.stage/project/verify, env.run | the same, and env.run |
env.step, observe, scene | agent.step, observe, scene; scene(elements=True) adds the interactive elements | scene({ elements: true }) |
env.render(w, h) → RGBA | agent.render(w, h) → PNG bytes with .etag, .state_hash, .tick | { bytes, etag, stateHash, tick } |
env.step then env.render | agent.step(actions, render={"if_changed": True}) → the step with frame (a base64 PNG) | agent.step(actions, { render: { ifChanged: true } }) |
an owner's filesystem.v1 session | env.write_file(path, text | bytes), env.read_file(path) | env.writeFile(path, text | Uint8Array), env.readFile(path) |
create_environment(..., idle_ttl=900) / createEnvironment(template, { idleTtl: 900 })
boots an environment that deletes itself after 900 s with no request (the hosted API).
Where an environment runs is the API's place, on Computaco's infrastructure: Lightning
(starts at once) first, and Heavy (room for big worlds and every application, counted in
Heavy-minutes) for a stated reason or when asked for (Places).
place="heavy" / { place: 'heavy' } on create_environment, import_environment and fork
asks for one: lightning, heavy, a Lightning place's id (core, office, media), or a
list of those tried in order (place=["heavy", "lightning"]). The environment's info
answers place (with its reason) and refused, the places that refused it first.
env.fork(place="lightning") moves a copy of a Heavy environment to Lightning.
An environment's history (History): a snapshot names its parent,
its author and the machines a picture was kept for (frames), read with
env.snapshot_frame(snapshot, machine) / env.snapshotFrame(snapshot, machine). restore
answers {state_hash, tick, head, elapsed_ms, conversations_kept, agents} and brings back the
agents and their conversations as the snapshot kept them (snapshot_agents(snapshot) /
snapshotAgents(snapshot) and snapshot_messages(snapshot, agent) /
snapshotMessages(snapshot, agent) read them without restoring); drop_snapshot /
dropSnapshot answers what is left, {snapshots, head}. env.history() is the whole family
(the furthest ancestor and every fork, each with its place, origin, head and snapshots).
env.fork(snapshot=...) / env.fork({ snapshot }) forks from a kept snapshot.
env.connect_agent(agent, machine) / env.connectAgent(agent, machine) connects an agent to a
machine and disconnect_agent / disconnectAgent disconnects it; the agent keeps its id,
token and thread.
client.models() and client.chat({...}) call the agent models on OpenAI's paths.
Client.signup(username, password, scopes=...) makes an account and then one API key with
its session, and returns a client holding the key with the account and the key as made
((client, user, key) in Python, { client, user, key } in JavaScript, server side only).
create_key(name, scopes=[...]) / createKey(name, { scopes }) make another; a key's scopes
are any of environments, templates, models and account, every one when left out, and
a call outside them raises the API's 403 scope_missing (the hosted API).
Beyond the engine's calls: the account (me, profile, usage, keys), templates and their
topology edits, advance on the environment's clock, service state, a grounded perform,
the environment's agents (external, hosted and simulated) and their threads, and its society (boot with society=,
then its rounds, the journal, the trace and the summary of its forks).
Agent.connect(token, environment_id, agent_id) builds an agent's handle from an actor
token alone, which can only step, observe, read the scene, render, and read and write its
own thread.
Agents' threads and hosted agents#
Every agent has a thread (the hosted API): agent.messages(after, wait)
reads it ({messages, state}), agent.prompt(text) adds the owner's prompt, agent.stop()
stops it, and agent.stream() follows it as it grows by long-polling, ending when its until
says so. env.hosted_agent(machine) / env.hostedAgent(machine) makes an agent the platform
runs (Computatrum's agent loop); an external agent's actor token writes its own thread with
agent.post(role, text, **fields) / agent.post({ role, text, … }); env.person(id) is a
handle on one of the society's people, for its thread.
agent = env.hosted_agent("workstation", name="typist")
agent.prompt("Open the Text Editor and type a greeting.")
for m in agent.stream(until=lambda m, state: m["role"] == "status" and m["status"] != "started"):
print(m["seq"], m["role"], m["text"])
const agent = await env.hostedAgent('workstation', { name: 'typist' });
await agent.prompt('Open the Text Editor and type a greeting.');
for await (const m of agent.stream({ until: (m) => m.role === 'status' && m.status !== 'started' })) console.log(m.seq, m.role, m.text);
The browser#
client.browser is the browser. Its one-call reads are screenshot,
content, markdown, links and snapshot, each taking the address and viewport,
wait_ms / waitMs and (for the pictures) full_page / fullPage. A screenshot is its PNG
bytes with width, height and clipped. create_session(url) / createSession({ url })
opens a session, which has act(actions), navigate(url), screenshot(), content(),
markdown(), links() and delete(); a Python session deletes itself at the end of a with.
client.browser.screenshot("https://example.com/", full_page=True).save("page.png")
with client.browser.create_session("https://example.com/") as s:
s.navigate("https://example.org/")
print(s.links()["links"])
const shot = await client.browser.screenshot('https://example.com/', { fullPage: true });
const s = await client.browser.createSession({ url: 'https://example.com/' });
await s.navigate('https://example.org/');
await s.delete();
Behaviour both share#
- Finding and clicking.
findreturns the frontmost interactive element matching every field given amonglabel,role,interactionandvalue(a string exactly, a regular expression by search), skipping disabled ones; a miss raisesElementNotFoundnaming what is on screen.clicktakes a point, an element, or the same fields and sends apointer.v1 clickat the element's centre in the environment's viewport (1280×800 unless changed). The helpers raiseActionFailedon an unsuccessful outcome;stepitself never does, as in the engine. - Retries. A 429, or a 503 with
Retry-After, is sent again for any method; a 500, 502, 504, a 503 withoutRetry-After(a failure on our side) or a lost connection only for GET, PUT and DELETE, so a POST that may have changed an environment is not repeated. The wait isRetry-Afterwhen sent, otherwise exponential backoff from 0.5 s, jittered and capped at 30 s; four retries by default, and aRetry-Afterlonger than 120 s is raised at once. - Errors carry the HTTP status and the API's
code(not_found,rate_limited,quota_exceeded,invalid_definition, …), its message,Retry-Afterand the request's method and path. An answer that is not the API's JSON ishttp_<status>. - User-Agent. Every request from Python, Node, Bun or Deno sends
computerworld-cloud-python/<version>orcomputerworld-cloud-js/<version>, with the caller's own in front when given. The API refusesurllib's default User-Agent with403 error code: 1010. A browser sends its own, since a cross-originfetchmay not set one.
Measured#
The live smoke tests (python/tests/test_live.py, test/live.test.mjs)
boot agent-desktop, click the editor's launcher, type, render, snapshot, fork, run
legal-engagement in the fork (34 GUI actions, verified) and delete both environments. Client
side, from the US against the hosted API on 2026-10-28, median of three runs
each, in milliseconds:
| Python | JavaScript | |
|---|---|---|
boot agent-desktop | 2,360 | 3,181 |
| scene with elements | 194 | 128 |
| step (click) | 150 | 148 |
| step (type) | 117 | 92 |
| render 1280×800 PNG | 973 | 1,260 |
render, unchanged (304) | 88 | 95 |
| snapshot | 345 | 206 |
| fork | 3,345 | 2,453 |
procedure run legal-engagement | 644 | 526 |
The two clients are within the run-to-run spread of each other: boot, render and fork vary by a second or more between runs of the same client, because each lands on a new environment object.
Tests#
From a clone of ComputaCo/computerworld:
cd python && python -m unittest discover -s tests -v # 42 offline tests, a local mock
npm test # (at the root) 46 offline tests, a local mock
COMPUTERWORLD_API_KEY=cw_live_… python -m unittest tests/test_live.py -v # in python/
COMPUTERWORLD_API_KEY=cw_live_… npm run test:live # at the root