Screen and input
When an application has no page and no accessibility tree to read, the screen and the input devices are what remain. screen.* reads pixels and input.* sends keys and pointer events through the X server, which is what a person at the desktop does. Prefer web pages and desktop applications first: they address an element by its name and report what happened.
Capturing the screen
Section titled “Capturing the screen”screen.capture returns the screen as a JPEG, one to one with no resizing. window (a reference from windows.list) captures that window’s visible rectangle, and region (x, y, width, height) captures part of the screen. Choose at most one. A crop’s origin is in the result: add origin_x and origin_y to a point in the image to get the input point. It needs no model.
The agent canvas
Section titled “The agent canvas”A caller that works from screenshots can send X-Kasm-Runtime-Coordinates: agent (stdio: KASM_RUNTIME_COORDINATES=agent). The screen is then fitted into a fixed 1280 by 800 canvas at its own aspect ratio, and points you send to input.*, and points screen.ground returns, are canvas points that the runtime converts. A point in the black bars is outside the screen. A coordinate action is refused when the screen’s size changed since your last capture, window list or grounding; capture again.
Waiting for the screen
Section titled “Waiting for the screen”For an application with nothing else to wait on, screen.mark takes a frame, and screen.wait waits until the screen has changed since that frame (until: "changed", with since) or has stopped moving (until: "settled"), up to timeout_s. window limits the comparison to one window’s rectangle, so a video elsewhere does not keep the screen busy. A timeout is matched: false, not an error. changed says pixels changed, not which action changed them, and settled says the screen stopped, not that an operation finished.
Keys, pointer and text
Section titled “Keys, pointer and text”| Method | Does |
|---|---|
input.key |
Presses a chord such as ctrl+s |
input.click |
Clicks at x, y; button, count (1 to 3) and modifiers are optional |
input.move |
Moves the pointer |
input.drag |
Drags from one point to another in steps moves |
input.scroll |
Turns the wheel in notches at a point |
input.type |
Types text one key per character |
A point off the screen, or an input the X server does not accept, is a resolution error. input.type holds each key key_hold_ms (default 15) and presses the next keystroke_ms (default 30) later, so 2,000 characters take about 90 seconds.
For long text, clipboard.set followed by input.key with ctrl+v is much faster and safer for text with line breaks. clipboard.get after ctrl+c reads back text from an application with no accessibility tree. The clipboard text is redacted for registered secrets and only its length is recorded in the report.
Observing input
Section titled “Observing input”With KASM_RUNTIME_OBSERVE_INPUT=true, the runtime records every key and button event the session’s X server receives, from the Kasm viewer, the runtime itself or another program. Two methods use the record:
input.cursorreturns the newest event number.input.wait_forwaits fortext, akeychord or aclicksince a cursor and returns what matched.timeout_msdefaults to 5,000 and is capped at 60,000.originisexternalby default (not the runtime’s own input),runtimeorany.
Take the cursor first, act, then wait, so input that arrives before the wait starts still matches. A match shows the input reached the X server; it does not show the right window got it, so a test pairs it with a check on the application, such as dom.wait.
Keystrokes are recorded verbatim, so turning observation on also requires a token to read the activity record. Key events recorded while the runtime itself types carry no key or text.
Vision methods
Section titled “Vision methods”Three methods ask a vision model about the screen.
| Method | Asks | Returns |
|---|---|---|
screen.judge |
Whether an expectation holds |
Holds and a description |
screen.ground |
Where a described element is | Found, X, Y; it does not click |
screen.ask |
A free-form question |
A plain-text answer |
screen.ground gives a location. Pass its X and Y to input.click. When the element is not visible it returns Found: false with no point. screen.ask sends the screenshot, and text from the browser tab in front when there is one, and the accessibility tree’s actionable elements.
Where the answers come from
Section titled “Where the answers come from”These are the only methods that need a model, and the runtime picks one in this order:
- The endpoint in
KASM_RUNTIME_VISION_ENDPOINT, any OpenAI-compatible server, hosted or your own. When set, it is always used. Gemma 4 is a model that works well here. See Vision models. - With no endpoint, a signed-in Claude Code agent in the workspace answers
screen.judge,screen.groundandscreen.askwith a small Claude model on the same account. Each call sends the frame to that model’s provider on the user’s credential. Codex and OpenCode do not provide this.KASM_RUNTIME_HARNESS_VISION=offturns it off. - With neither, the three methods return a resolution error that says no vision backend is available. Every other method works.
When you need a model compares the options across all three ways to drive a session.