Skip to content
Draft, pre-release documentation

Kasm Session Runtime is one binary, kasm-session-runtime. Its first argument picks what it does. Most settings come from the environment; see Environment variables.

Invocation What it does Needs a model
run <scenario.yaml> [more.yaml ...] Runs one or more scenario files in the session and writes a report for each No. Steps that need visual judgement are recorded as not judged; a goal: needs one
mcp Serves the runtime’s methods so an outside agent or script can drive the session No. The vision methods need an endpoint or a signed-in Claude Code agent in the workspace
compile-plan <run output dir> [flags] Turns a finished goal: run’s report into a plan: block No. It runs offline
recipes <command> Lists, describes, runs, checks, builds and drafts recipes No
playbooks <command> Prints a playbook’s brief and records a rehearsal No
layout save, layout restore Saves which applications are open and where their windows are, and puts them back in the next session No
sandbox probe Reports the isolation tier the host gives the helper programs recipes call No
recipe-worker install, recipe-worker --check Installs the recipe worker into an image, or verifies an installed one No
input-target-script Prints the page script that detects a focused text field No
viewer-host Runs the mobile emulation extension’s native messaging host No
(no arguments, or arguments that are not a subcommand) Runs one scenario taken from KASM_RUNTIME_SCENARIO_B64, or the default scenario when that is empty No, as for run
--version Prints the binary version and the report schema, then exits No

--version (or -version) counts only when it is the whole argument list. It prints a line of this form:

kasm-session-runtime 0.0.0-dev (report schema nix-testbench-report/1)

The runtime also starts itself as sandbox-exec to launch each helper program inside its sandbox. That mode takes no arguments from a person.

Terminal window
kasm-session-runtime run login.yaml checkout.yaml

Runs each scenario file in turn in the same session, with no reset between them. A scenario that needs a clean state sets it up with its own steps.

  • KASM_RUNTIME_APP is required. It fills in each scenario’s app, window and process when the file leaves them out.
  • KASM_RUNTIME_SCENARIO_B64 is ignored; the scenarios come from the files.
  • KASM_RUNTIME_DEADLINE_S bounds the whole invocation. Each scenario gets whatever time is left, and a later scenario may be refused with “session deadline exhausted before this scenario could start”.
  • Each scenario writes to its own directory, $KASM_RUNTIME_OUT/<name>/, where <name> is the file’s base name without its extension. Two files with the same base name get <name>, <name>-2, and so on.
  • After the last scenario, run writes summary.json and then DONE at the top of the output directory. The top-level verdict is the worst of the scenario verdicts. See Report for the layout.
  • A file that cannot be read or does not parse gets a test-error report in its own directory, and the rest still run.
  • SIGTERM or SIGINT (Ctrl-C) stops the scenario in progress. It still writes its report, with verdict test-error and outcome interrupted. Scenarios not yet started get a report saying so, and summary.json still lands.
  • With KASM_RUNTIME_OBSERVE=true, the run also serves the read-only observe routes the sidebar watches. See Sidebar protocol.

With no scenario files, run writes a test-error report saying it needs at least one, and exits 2.

run, mcp and the no-argument invocation take a lock on the output directory before they write anything. The lock is a .claim file holding the owner’s process id, held until the process exits. A second process aimed at a directory that a live process holds exits 2 and writes nothing, so it cannot overwrite the live process’s trace, report or DONE. The message names the owner and tells you to set KASM_RUNTIME_OUT to another directory.

This matters inside a session: the runtime’s own server holds the session’s output directory, so a scenario started from a shell in the same session needs its own KASM_RUNTIME_OUT. A directory with no live owner is taken over, so a lock left by a process that died does not block the next run.

Terminal window
kasm-session-runtime mcp

Serves the runtime’s methods over MCP and over plain HTTP, so an outside agent or script can drive whatever is on screen. It takes no arguments and runs no scenario.

  • With KASM_RUNTIME_SESSION_TOKEN empty, it speaks MCP over stdin and stdout and ends when the client closes stdin.
  • With KASM_RUNTIME_SESSION_TOKEN set, it serves HTTP on KASM_RUNTIME_BIND_ADDR:KASM_SESSION_RUNTIME_PORT (default 0.0.0.0:9434). Every acting request must carry the token in the X-Kasm-Runtime-Session-Token header. The same listener serves the observe routes, the HTTP API, and, with KASM_ENABLE_CDP=true, a raw DevTools proxy at /cdp/<name>/.
  • KASM_RUNTIME_APP is optional; it defaults to session.
  • KASM_RUNTIME_SCENARIO_B64 may still carry a scenario. It is not run; it only supplies declared names that the input and accessibility methods can resolve.
  • There is no deadline unless KASM_RUNTIME_DEADLINE_S is set explicitly. When it is set, the server stops itself at that point.
  • It waits up to timing.lifecycle.mcp_boot_timeout_s (30 seconds by default) for the X display before it fails.
  • On exit it writes report.json, report.md, trace.jsonl and DONE to KASM_RUNTIME_OUT. With no scenario, the verdict reflects the runtime’s own health: pass for a clean stop (a signal or the client closing stdin), test-error for a start-up or transport failure.

The methods are listed in MCP methods and the HTTP routes in HTTP API.

Terminal window
kasm-session-runtime compile-plan out/login --scenario login.yaml > login-with-plan.yaml

Reads report.json (and, if present, trace.jsonl for the run id) from a finished goal: run’s output directory and prints a plan: block to stdout: the actions the runtime’s loop took, in order, each with a postcondition inferred from what the loop checked afterwards. It makes no model call and needs no session, though the run it reads needed a model. See Plans and postconditions.

Flag Default What it does
--scenario <file> none Prints this base scenario with the compiled plan appended, and checks that the result parses. The base scenario must have a goal: and must not already have a plan:
--allow-incomplete false Compiles even when the run’s model verdict was not goal-met. Without it, such a run is refused

Flags may come before or after the directory argument.

The output lists, in a comment header, the transcript rows it left out and why. A plan step whose postcondition could not be inferred is printed with a TODO for you to fill in.

Recipes are checked operations an agent can call. index, list, describe, guide and run talk to the running runtime on 127.0.0.1 at KASM_SESSION_RUNTIME_PORT (default 9434) and need KASM_RUNTIME_SESSION_TOKEN in the environment. check, build and draft work on files and need no token.

recipes index
recipes list
recipes describe ID
recipes guide PATH
recipes run [--trace] [--resume FILE] ID < arguments.json
recipes check [DIR]
recipes build [DIR]
recipes build --from-json DIR
recipes draft --from-trace RECEIPT
Command What it does
index Prints the recipe index. Start here
list Lists every recipe operation the runtime has
describe ID Prints one operation’s description, arguments and result
guide PATH Prints a guide. The index gives the PATH of each guide
run ID Runs an operation. The arguments are one JSON object on standard input, at most 64 KiB. Prints the receipt as JSON
check [DIR] Validates recipe packages under DIR, or the user recipes directory (KASM_RUNTIME_RECIPES_DIR) when none is given, and prints a JSON report
build [DIR] Builds every typed package under DIR (default the current directory) into its recipe.json, and prints a JSON report. It runs no author code
build --from-json DIR Writes typed source for one hand-written package
draft --from-trace RECEIPT Drafts a recipe skeleton from a receipt saved from a run, and prints it as JSON

run flags:

Flag What it does
--trace After the receipt, prints a readable trace of the run on standard error
--resume FILE Answers a needs_decision receipt. FILE holds {"resume": "<token>", "decisions": {...}}. Run the same operation with the same arguments

run sends the agent coordinate space when KASM_RUNTIME_COORDINATES=agent is set. See Environment variables.

Exit codes for run:

Code Receipt outcome
0 verified
1 unverified, or the runtime answered with an HTTP error
2 Bad arguments, no usable receipt, or the call failed in transport, so the outcome may be unknown
3 refused
4 needs_decision

Only verified is success. The other subcommands exit 0 on success, 1 when a check or build found problems, and 2 for bad arguments. The receipt and its outcomes are in Recipes.

playbooks brief ID [--input TEXT | --source PATH ...] [--choice OPTION] [--context TEXT]
playbooks rehearsal ID --since RFC3339 [--until RFC3339] [--model NAME] [--kind rehearsal|run]

brief prints the exact brief the sidebar sends to the agent when a person starts the playbook, so an author can rehearse with the same text. It runs offline.

Flag What it does
--input TEXT The typed input. Cannot be combined with --source
--source PATH A chosen source path. Repeat it for several. Cannot be combined with --input
--choice OPTION The pick for a playbook that has a dropdown. It must be one of the playbook’s options
--context TEXT Optional extra context from the person

rehearsal asks the running runtime to score the recipe receipts a run produced and record the result on a personal playbook. It needs KASM_RUNTIME_SESSION_TOKEN.

Flag Default What it does
--since required When the run started, in RFC 3339
--until now When it ended, in RFC 3339
--model none The name of the model that did the work, recorded with the result
--kind rehearsal rehearsal or run

Both exit 0 on success, 1 when the playbook is unknown or the runtime refuses, and 2 for bad arguments. See Playbooks.

Terminal window
kasm-session-runtime layout save
kasm-session-runtime layout restore

Keeps a desktop session’s layout across sessions with a persistent profile: which applications were open and where their windows were. What is inside each window, such as a browser’s tabs, stays the application’s own job. It is for desktop images only. Single-application images, which open their one application maximized in every session, must not run either command: a restore would start that application a second time or fight its placement. Neither opens a port, starts the MCP server or needs a session token, and neither reads the operator file.

Run layout save as a service of its own. It writes ~/.config/kasm-session/layout.jsonl every 10 seconds when the layout changed in something other than the windows’ titles, once this session’s restore has read the last layout (at most a minute after it starts), so a page or document title that changes alone does not rewrite the file. When it receives SIGTERM or SIGINT it exits 0 without saving: at a session’s end the applications are stopping too, and the file keeps the last save before that. It writes nothing when no application window is open, so a session whose applications were closed before it ended keeps the last layout. Each write replaces the file in one step, so a session killed mid-write leaves the previous file whole.

Run layout restore once when the session starts, from the desktop’s autostart, so the applications it starts belong to the desktop as if started from the menu. It starts each recorded application that is not already running straight away. It then waits for the viewer’s first resize of the screen, or 5 seconds without one, and puts each window back where the file says, scaled to the current screen size and kept on screen. A window that is already within a few pixels of its place, because the application restored it itself, is left alone. If the first resize comes later, within 2 minutes, the windows still where the restore put them are scaled again. Without a layout file it does nothing. It exits 0 whatever it could restore.

Flag Applies to Default What it does
--file <path> both ~/.config/kasm-session/layout.jsonl The layout file
--interval <duration> save 10s How often to save
--once save false Save once and exit
--again restore false Restore even when this session already did

The file is JSON Lines, one line per application, in a fixed order so the same layout always gives the same bytes. A person can read it, delete one application’s line, or delete the file to forget the layout. KASM_LAYOUT_RESTORE=0 turns both off for a session; see Environment variables.

Terminal window
kasm-session-runtime sandbox probe
kasm-session-runtime sandbox probe --json

Runs the same check the runtime makes before it launches a helper program, and reports the isolation tier the host gives. It always exits 0 once it has probed, and 2 for any other arguments.

Tier Meaning
full Landlock ABI 6 or later, with seccomp
partial Landlock ABI 1 to 5. Seccomp stands in for the missing rights
none No Landlock, so no filesystem confinement. Seccomp is in place
isolation_unavailable Not even seccomp could be installed. Helpers do not run

The text form prints helpers:, then tier: with the Landlock ABI, seccomp:, and a reduced isolation: list of the gaps. With --json it prints one line with the keys helpers (available or isolation_unavailable), tier, landlock_abi, seccomp and reason.

Terminal window
kasm-session-runtime recipe-worker install [--dir DIR]
kasm-session-runtime recipe-worker --check [--dir DIR]

Image builders run these. install writes the recipe worker and its library into DIR (default /usr/local/libexec/kasm-session-runtime), verifies both against this runtime and runs the worker’s own check. Run it once, as root, after the runtime binary is in place. --check verifies an installed worker without writing: the one in DIR, or without --dir the one this runtime would use. KASM_RUNTIME_RECIPE_WORKER overrides which worker the runtime uses; see Environment variables.

Exit codes: 0 installed or verified, 1 failed, 2 bad arguments, 3 the image lacks the C library loader the worker needs.

Terminal window
kasm-session-runtime input-target-script > input-target.js

Prints the page script that detects whether the focused page element takes text. It reads no field values. It needs no session, display, token or browser, and takes no arguments. The mobile emulation extension and the runtime use the same script, so the extension’s build takes it from the release binary. It exits 0.

Runs the native messaging host of the Kasm mobile emulation extension. Chrome starts it by path, so an image links the binary under the name kasm-viewer-host; the runtime runs this mode for that name whatever its arguments. It reads and writes the extension’s messages on standard input and output, opens no listener, needs no token and ends when the extension closes the port. It needs DISPLAY, and DBUS_SESSION_BUS_ADDRESS for the desktop’s settings store. KASM_MOBILE_DETECT=0 turns it off.

Code run and no-argument invocation mcp compile-plan
0 Verdict pass or pass-with-concerns Clean stop Plan printed
1 Verdict app-failed Not used Refused or incomplete: model verdict not goal-met, a step with no inferable postcondition, no compilable rows, or the combined scenario does not parse. What could be compiled is still printed
2 Verdict test-error, a configuration or scenario error, an output directory held by another live process, or a failure to write the report or DONE Start-up or transport failure, or a failure to write the report Bad arguments, or a file that cannot be read or parsed

layout save exits 0 when it stops on a signal, and with --once 1 when the save failed. layout restore exits 0. Both exit 2 for bad arguments. The recipes, playbooks, sandbox, recipe-worker and input-target-script codes are in their sections above.

For run with several files the code follows the worst verdict. If any scenario’s evidence is incomplete, or summary.json or DONE cannot be written, the code is 2 whatever the verdicts were.