Skip to content
Rather not run it yourself? OpenRMM Cloud hosts it for you.

Agent Protocol

The agent maintains one persistent WebSocket to /ws/agent. Every frame is a JSON Envelope:

{ "type": "<message type>", "data": { ... } }

Defined in internal/protocol.

  1. Agent → register:
    • Explicit one-shot enrollment (-enroll-only): { "enroll_token": "...", "hostname", "os", "arch", "version", "device_public_key?": "..." }
    • Later: { "agent_id": "...", "agent_token": "...", "hostname", ..., "device_public_key?": "...", "device_key_status?": "unavailable" }
    • Both may carry computer_name: a Mac’s Computer Name (System Settings → General → Sharing), beside the hostname its OS reports. Other OSes and older agents omit it. The server keeps it only for a device enrolled as a Mac (whatever OS a later registration claims), without control, invisible formatting or line separator characters and at most 255 characters, and devices.macos_name chooses which of the two names the console shows.
  2. Server validates (consumes the enroll token, or verifies the token hash) and replies:
    • registered → { "agent_id": "...", "agent_token": "...", "cancel_credential_rotation_id?": "..." } (the token is only returned on first enrollment; the agent persists it)
    • or error → { "error": "..." } and closes.

The agent stores {agent_id, agent_token, device_private_key, device_public_key} in its state file (-state, default agent-state.json, mode 0600) and re-authenticates with it on reconnect. A damaged device_private_key is never overwritten: the agent still connects with device_key_status: "unavailable" so jobs, monitoring and updates keep running while native remote sessions pause for administrator review (08-remote-access). Run rmm-agent -state <path> -fingerprint to print the stored key’s fingerprint without creating or modifying the state file. A long-lived service never enrolls from -enroll-token; installers run -enroll-only before creating the service so a deleted state file cannot reuse a bootstrap token.

Production installers first perform this one-shot enrollment, then install the long-lived service without the enrollment token in its arguments. They require an HTTPS origin and --update-public-key/-UpdatePublicKey (on Linux and macOS, OpenSSL 3 or the manifest’s P-256 key in --manifest-public-key), and set -require-tls -update-verify strict. Plain HTTP or missing update trust is available only through explicit lab mode.

type data effect
heartbeat { logged_in_user? } refresh last_seen, mark online; agent 0.11+ sends the interactive user (DOMAIN\user on Windows, "" when no one is logged in), which the server cleans (control and invisible characters removed, 256 characters at most) and stores. A non-empty user is also kept as the last logged-in user, which "" does not clear. An agent that omits the field (older agents send {}) leaves the stored user alone
inventory { "data": {...} } upsert the inventory snapshot
job_result { job_id, exit_code, stdout, stderr, success } finalize the job (server replies job_result_ack)
patch_report { os, patches:[{identifier,title,classification,kb,reboot_required,...}] } upsert the device’s missing patches (16)
patch_result { request_id, results:[{identifier,success,reboot_required,error}], reboot_required } record an install run
check_result { check_id, execution_id, value, output, success, timed_out } record one check run; the server replies check_result_ack. value carries the number for threshold checks (free %, load %, exit code), success the verdict for boolean ones (reachable / running / exit == 0). timed_out (agent 0.12.0) says the agent stopped the run at the check’s timeout, so the check’s timeout policy applies
remote_status (reserved) native remote-session state
credential_rotated { rotation_id } confirm durable replacement storage; replacement-token reconnect commits it
credential_rotation_canceled { rotation_id } confirm durable restoration; re-sent until credential_rotation_canceled_ack arrives

The reference agent sends a heartbeat every 20s and inventory every 5min (and once on connect).

At each registration the server refreshes the hostname, architecture and version the agent reports, but keeps the OS the device enrolled with (an OS never recorded is filled in): policy assignments filter on it, so a device naming another OS is not believed (10).

The logged-in user is read on each heartbeat. On Windows it is the user of the physical console session when someone is logged in there, else the first active remote desktop session (disconnected sessions do not count), as DOMAIN\user — AzureAD\user for an Entra ID account, the computer name for a local one. On macOS it is the owner of /dev/console (no one at the login window). On Linux it is the user of a systemd-logind session: the active one on a seat (the console or the graphical login) first, then another local session, else one connected over SSH. The login screen, the lock screen and the service managers do not count. Without logind, utmp is read the same way.

An online agent has an authenticated control connection; that does not confirm its inventory was stored. For a known, accessible device, a 404 from GET /api/devices/{id}/inventory means there is no stored snapshot yet.

The agent logs inventory: collection started and, after collection and JSON encoding, inventory: snapshot queued with the byte count and elapsed time. Queueing is not a persistence acknowledgement. An encoding failure is logged and no empty frame is sent. Unknown disk or memory usage percentages are reported as null, leaving the rest of the snapshot available.

The server logs inventory: snapshot stored only after a successful database write. Rejected messages produce inventory: invalid snapshot; database errors produce inventory: persistence failed, with the agent ID and PostgreSQL SQLSTATE where available. Snapshot contents and database error details are not logged. The last valid snapshot remains available if a later write fails. Embedded NUL characters in text values are removed before JSONB storage, also for older agents; literal backslash sequences and numeric precision are kept. Before allocating the normalized snapshot, the server enforces an 8 MiB input limit, a maximum nesting depth of 32, and at most 50,000 JSON tokens (including keys, values and container delimiters). These bounds accommodate the reference agent’s maximum of 600 software entries and reject excessive structure before building a large object graph. A rejected snapshot does not replace prior data.

When diagnosing missing inventory, compare the agent’s agent.log beside its binary (Windows/macOS services) or its service journal (Linux) with the server logs around the same connection time. A collection-start message without a queued snapshot points to collection or encoding; a queued snapshot without a stored message requires checking delivery and server-side diagnostics. Allow one collection cycle after deploying a fix; reinstalling the device is not normally necessary.

type data effect
job { job_id, type, shell, script, params? } run it, reply with job_result. type device_query runs a built-in query instead of a shell; params are a released script’s parameters (see below)
job_result_ack { job_id } confirm a job_result was durably recorded; the agent drops it from its retry outbox
check_result_ack { execution_id } same for a check_result, keyed by the execution rather than the check: a result may be re-sent until it is acknowledged
remote_start { session_id, agent_ticket, kind, allow_files, no_chat?, e2e?, viewer_key?, guest_mode? } connect a remote module to the relay; the agent derives /ws/remote from its own control WebSocket origin. When e2e is true, the agent/sidecar signs an ephemeral delegation with its device identity key and binds the handshake to viewer_key (and guest_mode enforces view/control restrictions locally on the endpoint)
credential_rotate { rotation_id, agent_token } durably store the replacement credential, then reconnect with it
credential_rotation_cancel { rotation_id } durably restore the prior credential and confirm it
credential_rotation_canceled_ack { rotation_id } server recorded restoration; drop the persisted confirmation retry
job_cancel { job_id } stop a job: reject it if it has not started, or kill the running process
run_check { check_id, execution_id, type, config, timeout_sec } run one monitoring check now, reply with check_result. execution_id identifies this run, so a retry is recognised as the same observation rather than a new one (10)
patch_scan {} scan for missing OS patches, reply with patch_report
patch_install { request_id, identifiers } install only the explicit approved identifiers; an empty list is rejected, reply with patch_result
reboot { delay_seconds } reboot the host

kind selects which module the agent attaches: "desktop" (or empty) spawns the media sidecar (screen + input); "files" spawns the same sidecar in file-transfer-only mode (no screen capture); "terminal" opens an elevated interactive shell in the agent process (real PTY on Unix / ConPTY on Windows) and bridges it to the relay. See 08-remote-access.

Credential rotation and cancellation require agent version 0.4.5 or later. Only one server-initiated rotation may be pending for an endpoint. On receiving credential_rotate, the agent atomically writes the replacement token and its rotation_id, acknowledges durable persistence, and reconnects with the replacement; that reconnect is the commit point. The server first persists a cancellation fence before sending credential_rotation_cancel, so an ACK or replacement-token reconnect cannot win after cancellation starts. The agent persists its restoration confirmation and retries it after reconnects until the server replies with credential_rotation_canceled_ack. A reconnect while a cancellation is pending carries cancel_credential_rotation_id in registered, so the agent restores its prior credential before clearing local rotation state. A different later credential_rotate implicitly confirms the preceding cancellation, because the server cannot stage it until the older rotation is gone.

Deploy the server first, publish the ticket-aware sidecar, then update agents. Current peers use the session id plus a handshake ticket. During rollout only, an agent can launch a cached pre-ticket sidecar through the agent-only legacy relay path when RMM_ALLOW_LEGACY_AGENT_RELAY=true; browser viewers never use this fallback and never place a ticket in a URL. Set the flag back to false after the fleet has the ticket-aware sidecar.

  • The server sets a 90s read deadline and sends WebSocket pings every 30s; the agent’s pong resets the deadline. Dead links are detected and cleaned up.
  • Approved jobs for an offline agent stay pending and are delivered on reconnect (DispatchPending).
  • Job results are delivered at-least-once. The agent keeps each job_result in a disk-backed outbox and re-sends it on every (re)connect and on the heartbeat timer until the server replies job_result_ack. This means a connection dropped between execution and delivery — or an agent restart — can’t strand a finished job in sent; the result is redelivered and the job finalizes automatically. The server’s handling is idempotent (a re-sent result for an already-terminal job is a no-op but is still acked), so duplicates are harmless. (For a result that never arrives at all, an operator can still force the outcome via manual complete — POST /api/jobs/{id}/complete, see 04-api-reference.)
  • The agent reconnects automatically with a 5s backoff.

The agent periodically checks /dl/rmm-agent-<os>-<arch> (HEAD, ETag) and, when the published build changes, downloads it, verifies its detached Ed25519 signature when configured, validates it, atomically swaps the binary, and reloads (re-exec on Unix; a detached service restart on Windows). Disable with RMM_AUTO_UPDATE=0; tune the cadence with RMM_UPDATE_INTERVAL (default 30m). Use RMM_UPDATE_VERIFY=strict and RMM_UPDATE_PUBLIC_KEY for production. See 02-getting-started and 13-security-rollout.

The installer verifies both the signed SHA256SUMS manifest and the selected artifact signature. Runtime self-update verifies the artifact’s detached signature. The configured public key must match the release signing key; a checksum fetched from the same untrusted origin is not sufficient by itself.

The agent maps shell to an interpreter:

shell command
powershell powershell -NoProfile -NonInteractive -Command <script>
cmd cmd /C <script>
sh sh -c <script>
bash (default) bash -c <script>
python the resolved interpreter, run against a staged file (see below)

An unknown shell is refused with exit 2 rather than falling back to Bash, so a typo never runs under an interpreter the operator did not choose.

Device queries and parameters (agent 0.10.0)

Section titled “Device queries and parameters (agent 0.10.0)”

A job of type device_query carries {"query": ..., "params": {...}} as its script. The agent runs fixed, read-only code for that query and replies with its result as JSON on stdout (at most 64 KB). The query and its parameters are checked against the catalog by the agent as well as the server (internal/protocol/devicequery.go); nothing in them reaches a command line except a whole number of hours, formatted by the agent. See 23-ai-autonomy. Autonomous job frames also carry expires_at (an absolute RFC 3339 start deadline). The agent refuses a frame whose deadline has passed; ordinary human-approved jobs omit this field and keep their reconnect delivery behavior.

params on a run_script job are a library script’s declared parameters. The agent sets each one as the environment variable OPENRMM_PARAM_<NAME> for the script’s process and never splices it into the script text. It refuses a name that is not [a-z][a-z0-9_]{0,31}, a value over 200 characters or holding a line break, and any parameter on a cmd job (cmd expands variables into its own command line). Agents before 0.10.0 ignore params, which is why the server refuses parameterised jobs and device queries for them.

Execution is bounded by a 10-minute timeout; stdout/stderr and the exit code are returned.

Python is the one shell that is staged to a file — openrmm-script-*.py, mode 0600, removed when the run ends, including on timeout or operator cancel. Passing it with -c would work until it didn’t: a traceback would point at <string> instead of a file and line, Windows caps a command line at ~32k characters, and a script full of quotes and newlines is one quoting mistake away from running as something else.

The interpreter is resolved at run time, in order: python3, then python, then py -3 on Windows only. python3 comes first because on a machine with both, python may still be Python 2 — under which a Python 3 script fails in ways that read like a syntax error in the operator’s code. The py launcher is the reliable way to reach an interpreter that is installed but absent from PATH.

A device with no interpreter exits 127 (the shell convention for “command not found”) and says which candidates were tried. That is deliberately distinct from a script failure: “this device has no Python” and “this script is broken” are fixed by different people in different places.

Python scripts require agent 0.4.9 or later. Older agents answer “unsupported shell”, so the server refuses the job before dispatch instead — see models.MinAgentVersionFor. A bulk deployment naming any outdated device is refused whole, listing the devices to update, rather than creating jobs for part of the selection behind an approval granted for all of it.

A redirected child process on Windows writes in the system code page, not UTF-8: Python resolves locale.getpreferredencoding() (cp1252 on a pt-BR install), cmd and Windows PowerShell use the OEM page. Accented bytes are then not valid UTF-8 on their own, and marshalling them as JSON replaces each with U+FFFD — a lossy substitution, so Olá, café became Ol<?>, caf<?> in the database with no way to recover it downstream.

Two defences, in order of preference:

  1. Ask the interpreter. Python is run with PYTHONIOENCODING=utf-8 — the variable rather than -X utf8, whose Python 3.7 requirement would fail the whole script with “unknown option” on an older interpreter instead of merely mis-encoding its output.
  2. Decode what still is not UTF-8, using the code page the OS reports (GetConsoleOutputCP, falling back to GetACP), rather than discarding the byte. This covers cmd, Windows PowerShell and anything that ignores the request. Valid UTF-8 is passed through untouched.

Truncation of long output is rune-aware: slicing bytes at the cap used to split a multi-byte character and leave an invalid tail, which corrupted output from Linux and macOS agents too, not only Windows.