Enable the runtime on a workspace
Kasm Session Runtime starts in a session when the session has a token, and it reaches people and outside agents through a port map on the workspace. This page sets up both, for Kasm nix images and for stock kasmweb/* images. You need Kasm administrator access, to edit a workspace’s Docker run configuration.
No model is needed for any of this. An agent running outside the session brings its own, and a vision endpoint (When you need a model) is optional.
What a workspace needs
Section titled “What a workspace needs”| Setting | Where | Effect |
|---|---|---|
Port map entry named runtime |
Workspace Docker run configuration, custom_port_map |
Kasm’s proxy forwards /desktop/<kasm_id>/runtime/ to the runtime on container port 9434. The sidebar and every outside caller use it |
KASM_RUNTIME_SESSION_TOKEN |
Workspace environment, or the session request |
Starts the runtime. The same value is the credential an outside caller sends |
KASM_RUNTIME_SIDEBAR |
Workspace environment |
Optional. Picks the sidebar, or turns it off. See Replace the sidebar |
With no token the runtime does not start, and the session behaves like any other session of that image.
| Image | What you do |
|---|---|
Kasm nix images, for example chrome:nix |
The runtime is in the image. Set the port map and the environment |
Stock kasmweb/* images |
Build a thin layer that adds the runtime, then set the port map and the environment |
Register the port map
Section titled “Register the port map”Kasm reaches a service inside a session through a custom_port_map entry on the workspace. Open the workspace in the Kasm admin UI and add this to its Docker run configuration override :
{ "custom_port_map": { "runtime": { "container_port": "9434/tcp/http/none" } }}The value is one string, <port>/tcp/<scheme>/<auth>. none stops Kasm’s proxy adding Basic authentication of its own. Kasm’s session cookie still gates the path.
Kasm applies the change to sessions requested after it. Sessions already running do not get the port map.
Optional: the toolkit’s examples register the same entry through the Kasm API with an API key that has IMAGES_VIEW, IMAGES_MODIFY and IMAGES_MODIFY_RESOURCES. Run it from your copy of the examples with settings.env filled in:
uv run lib/kasm_provision.py ensure-port-map --ref <image> --port 9434 --service runtimeSet the environment
Section titled “Set the environment”Add an environment map to the same override . Generate the token as a long random value:
python3 -c 'import secrets; print(secrets.token_hex(16))'{ "custom_port_map": { "runtime": { "container_port": "9434/tcp/http/none" } }, "environment": { "KASM_RUNTIME_SESSION_TOKEN": "<your token>" }}A value set on the workspace is the same for every session of that workspace. To give each session its own token, leave it off the workspace and send it with the session request (One token per session).
With the token set, the viewer shows the runtime’s sidebar: a panel beside the desktop with the Workspace, Messaging, Activity and Details tabs. Anyone who can view the session can read its activity and message its agent. Add "KASM_RUNTIME_SIDEBAR": "off" to keep the stock viewer.
To put an agent in the workspace for people to work with, continue with Offer an agent in a workspace.
Stock kasmweb images
Section titled “Stock kasmweb images”The SDK’s stock_image_mods directory adds the runtime to a kasmweb/* image. Everything it adds stays off until an environment variable turns it on, so the built image behaves like the stock one by default.
Dockerfile.chrome and Dockerfile.libre-office are ready to build and differ only in BASE_IMAGE. From the stock_image_mods directory:
docker build -t kasmweb/chrome:stock-mods -f Dockerfile.chrome .The build:
- Declares the screen settings in
kasmvnc.yaml, so KasmVNC honours theKVNC_*variables below. - Downloads the pinned runtime release for the build architecture (amd64 or arm64), checks its SHA-256, and installs it with the bundled sidebar as the sidebar named
default. No registry login is needed. - Runs
kasm-session-runtime recipe-worker install, which installs the worker that executes recipe bodies. See Install recipes and playbooks. - Wraps the image’s startup so the runtime starts with the session when the token is set, and puts the screen and sidebar selection in front of the stock entrypoint.
For another kasmweb/* image, copy Dockerfile.chrome and change BASE_IMAGE. To use another runtime release, pass the RUNTIME_COMMIT, RUNTIME_TAG, RUNTIME_SHA256_AMD64, RUNTIME_SHA256_ARM64 and RUNTIME_SIDEBAR_SHA256 build arguments from that release’s release.json.
Push the image to a registry your Kasm deployment can pull from and add it as a workspace . Then set the port map and environment as above.
The layer adds no agent. To offer one, use a nix image (Offer an agent in a workspace).
Screen size
Section titled “Screen size”A model’s clicks and a baseline screenshot only hold at the screen size they were made at. A session with a vision endpoint therefore gets a fixed 1024×768 screen that viewers cannot resize.
| Variable | Effect | Unset |
|---|---|---|
KASM_RUNTIME_VISION_ENDPOINT |
Gives the runtime a model for screen.* and fixes the size and the resize lock as above |
Size follows the image, resizes allowed |
KASM_RUNTIME_SCREEN_SIZE=<W>x<H> |
Sets the screen size. off leaves the image default |
1024×768 with a vision endpoint |
VNC_FIXED_RESOLUTION |
1 refuses viewer resizes, 0 allows them even with an endpoint |
Refused with an endpoint, allowed without |
On stock images VNC_RESOLUTION has no effect and the screen is 1024×768 unless one of the variables above changes it. The KVNC_* variables set the same things directly and win over the three above:
| Variable | Effect | Unset |
|---|---|---|
KVNC_DESKTOP_RESOLUTION_WIDTH, KVNC_DESKTOP_RESOLUTION_HEIGHT |
Screen size | 1024×768 |
KVNC_DESKTOP_ALLOW_RESIZE=false |
Attached viewers cannot resize the desktop | Resize allowed |
On nix images Kasm sets VNC_RESOLUTION from the session request’s x_res and y_res and overwrites any value in the environment map. KASM_RUNTIME_SCREEN_SIZE takes its place.
Other settings
Section titled “Other settings”| Variable | Effect |
|---|---|
KASM_ENABLE_CDP=true |
Also exposes a raw Chrome DevTools Protocol proxy at /cdp/<name>/ on the same port, one route per application dom.targets lists, behind the same token. Ignored, with a log line, when no token is set |
KASM_RUNTIME_DISABLE_A11Y=1 |
Turns off accessibility, which is otherwise on in a session with a token. With it on, supported applications publish their controls over AT-SPI |
KASM_RUNTIME_SIDEBAR_TOKEN_TTL |
How long the sidebar’s sign-in file stays available, a duration such as 10m. Default five minutes |
The dom.* methods need a browser with a debugging port. On a nix image every browser and Electron application in a session with a token gets one, and dom.targets lists them by name, so there is nothing to set. On other images set APP_ARGS, which replaces the image’s default arguments:
{ "environment": { "APP_ARGS": "--start-maximized --test-type --ignore-certificate-errors --remote-debugging-port=9222 --remote-debugging-address=127.0.0.1 --remote-allow-origins=* --user-data-dir=/home/kasm-user/.config/chrome-cdp-profile" }}Keep --user-data-dir. Chrome 136 and later ignores --remote-debugging-port without it and gives no error. dom.targets then lists the browser as default.
One token per session
Section titled “One token per session”To give each session its own token, send KASM_RUNTIME_SESSION_TOKEN in the environment map of the Kasm API’s request_kasm call. Kasm keeps that map only when the call is authenticated with an API key. With a username and password the variables are dropped and no error comes back.
From the SDK’s examples directory:
TOKEN=$(python3 -c 'import secrets; print(secrets.token_hex(16))')eval "$(uv run lib/kasm_provision.py up --ref <image> --env KASM_RUNTIME_SESSION_TOKEN="$TOKEN")"The token is a credential for the whole session. Pass it to the agent that will use it and nowhere else. Your agent or script shows how a caller uses it.
Check it works
Section titled “Check it works”Start a session of the workspace.
-
The viewer shows the sidebar to the right of the desktop. Details shows the session’s mode and its vision configuration. With
KASM_RUNTIME_SIDEBAR=offthere is no panel. -
From a terminal in the session, send an MCP
initializerequest tohttp://127.0.0.1:9434/mcpwith the token header:Terminal window curl -s -X POST http://127.0.0.1:9434/mcp \-H "X-Kasm-Runtime-Session-Token: $KASM_RUNTIME_SESSION_TOKEN" \-H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' \-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"check","version":"0"}}}'The reply names
serverInfo.nameaskasm-session-runtime. A wrong token gets HTTP 401. -
From outside, the endpoint is
https://<kasm host>/desktop/<kasm_id>/runtime/mcp. A request carries Kasm’s session cookie and the token header.lib/kasm_provision.py mcp-connect --kasm-id <kasm_id> --token <your token>prints both with lines to paste into Claude Code and Codex.
On a stock image the runtime’s log is /tmp/kasm-session-runtime-mcp.log. A line containing serving N methods over HTTP on 0.0.0.0:9434 means it started.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause | Fix |
|---|---|---|
| HTTP 401 | The X-Kasm-Runtime-Session-Token header is missing or wrong |
Send the session’s token in that header. Kasm’s proxy overwrites Authorization before the request reaches the runtime |
| HTTP 502 | The runtime is still starting, or the workspace has no runtime port map |
Wait a few seconds. If it persists, check the port map and that the session was requested after you added it |
| The token never reaches the session | The session was requested through the API with a username and password | Request it with an API key |
| No sidebar | KASM_RUNTIME_SIDEBAR is off, malformed, or names a sidebar the image lacks; or the image predates the built-in sidebar |
Unset it or set default. An unknown name is logged with the installed names and the stock viewer loads |
| Stock image stays 1024×768 | Stock images ignore VNC_RESOLUTION |
Set KASM_RUNTIME_SCREEN_SIZE, or the KVNC_DESKTOP_RESOLUTION_* pair |
| The desktop does not follow the browser window | A vision endpoint is set, so resizes are refused | Set VNC_FIXED_RESOLUTION=0 for sessions a person uses |
dom.* cannot reach the browser |
The browser has no debugging port, or no --user-data-dir |
Start it from the desktop menu, or set APP_ARGS as above. Flags apply at Chrome’s first launch only |