Skip to content
Draft, pre-release documentation

A script can drive a session with nothing but HTTP requests. This page calls the runtime from Python, opens a page, clicks its link and checks where it landed. No agent and no model are involved.

  • A session requested with KASM_RUNTIME_SESSION_TOKEN set in its environment, on a workspace with the port map named runtime. Try it: Claude Code drives a session shows the request, and Enable the runtime on a workspace covers the workspace.
  • The session’s kasm_id, your Kasm URL, the session token and the Kasm login of the session’s owner.
  • Python 3 with requests.

The script reads its settings from the environment, so nothing secret is written into it. It logs in for the Kasm cookie, then makes one POST per method.

import os
import sys
import requests
kasm = os.environ["KASM_URL"].rstrip("/")
base = f"{kasm}/desktop/{os.environ['KASM_ID']}/runtime"
http = requests.Session()
login = http.post(
f"{kasm}/api/authenticate",
json={"username": os.environ["KASM_USERNAME"], "password": os.environ["KASM_PASSWORD"]},
timeout=30,
)
login.raise_for_status()
http.headers["X-Kasm-Runtime-Session-Token"] = os.environ["RUNTIME_TOKEN"]
def call(method, **params):
r = http.post(f"{base}/v1/call/{method}", json=params, timeout=120)
body = r.json()
if not r.ok:
sys.exit(f"{method}: HTTP {r.status_code} {body.get('error')}")
return body["result"]
# Pick Chrome's first page.
targets = call("dom.targets")
page = next(
p["page"]
for reg in targets["registrations"]
if reg["available"]
for p in reg["pages"]
)
call("dom.navigate", page=page, url="https://example.com/")
links = call("dom.list_interactive", page=page)["data"]["elements"]
link = next(e for e in links if e["role"] == "link")
call("dom.click", element=link["handle"])
call("dom.wait", page=page, predicate="location.href.includes('iana.org')", timeout_s=15)
print(call("dom.url", page=page)["data"]["url"])

Run it with the settings in the environment:

Terminal window
export KASM_URL=https://kasm.example.com KASM_ID=<kasm_id> KASM_USERNAME=<user>
read -rs -p 'Kasm password: ' KASM_PASSWORD; echo
read -rs -p 'Session token: ' RUNTIME_TOKEN; echo
export KASM_PASSWORD RUNTIME_TOKEN
python3 drive.py

It prints the address the click reached. Each call is a row in the sidebar’s Activity tab while it runs.

  • Every method is POST /v1/call/<method> with the parameters as the JSON body. A 200 returns {"result": ...}; an error returns {"error": {"class": ...}} with the status in the table on the overview.
  • dom.* methods need a page reference from dom.targets, or an element handle from dom.list_interactive. There is no default tab.
  • The click returns when it is delivered, so the script waits with dom.wait before reading the address.

A browser test can drive Kasm’s own viewer, clicking and typing on the desktop canvas, and then prove the input arrived. The 10-playwright-verify example in the toolkit does this with Playwright and the same HTTP calls. It starts the session with KASM_RUNTIME_OBSERVE_INPUT=true, takes input.cursor before it acts, and then checks two things:

  • input.wait_for confirms the click reached the session’s X server at the intended pixel and that the typed text arrived.
  • dom.wait confirms the application, a page with one text box, holds the text.

The X server receiving a keystroke does not show that the right window got it, so a test needs both checks. Screen and input describes input.cursor and input.wait_for.

Run the viewer at the session’s own size. A viewer shown at another size can move a click to a different pixel.