Guide · trust and architecture

How Keyrelay works, and what it trusts

Keyrelay is one standard-library Python file of 444 lines and a small npm launcher. This guide follows a key from your keyboard to the command, names every check on the way, and lists what Keyrelay leaves out of scope.

The path a key takes

  1. 1. Coding agentRuns keyrelay run --env NAME -- command as an ordinary tool call. It sees the printed link and, later, the command's output.
  2. 2. Runner (keyrelay run)Starts a temporary broker on 127.0.0.1, creates a request with the command and variable name, and receives a request ID plus a separate claim token. It prints only the link.
  3. 3. BrokerHolds the request in memory and serves the form. In local mode it lives inside the runner and stops once the key is collected.
  4. 4. Your browserShows the exact command and variable. You type the key and select Send once. The form clears its fields before it posts.
  5. 5. Runner againPolls every two seconds with its claim token, collects the key, and the broker deletes the request.
  6. 6. The commandReceives the key as $NAME or on standard input. Its output and exit status go back to the agent with exact echoes of the key replaced by [REDACTED].
  7. Optional: Tailscale modeWith --url, steps 3 and 4 move to a persistent broker behind Tailscale Serve, so you can use another device. The key still reaches only the command on the runner's machine. See Enter an API key from your phone.

What is checked

Who can open the form

Who can collect the key

The form page itself

How long a request lives

What redaction covers

Before output reaches the agent, Keyrelay replaces exact copies of the submitted value in standard output and standard error. With several fields, it also replaces each field value of four bytes or more; shorter values would redact ordinary text like yes. Anything the command transforms first, such as a base64 or URL-encoded copy, is not caught. Redaction is a safety net for accidental echoes, not a guarantee.

What Keyrelay does not protect against

Prefer scoped, short-lived credentials. Found a way for something other than the approved command to get a key? Report it through private vulnerability reporting.

Check it yourself

Everything above is in keyrelay.py. The checks live in handler_factory, the request lifecycle in route, claim and run, and redaction at the end of run. The test suite runs with python3 -m unittest discover -s tests.

Written for Keyrelay 0.1.6 and kept in step with the code by its maintainer, Cole Foster. If the code and this page disagree, the code wins: please open an issue.