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. Coding agentRuns
keyrelay run --env NAME -- commandas an ordinary tool call. It sees the printed link and, later, the command's output. - 2. Runner (
keyrelay run)Starts a temporary broker on127.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. 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. Your browserShows the exact command and variable. You type the key and select Send once. The form clears its fields before it posts.
- 5. Runner againPolls every two seconds with its claim token, collects the key, and the broker deletes the request.
- 6. The commandReceives the key as
$NAMEor on standard input. Its output and exit status go back to the agent with exact echoes of the key replaced by[REDACTED]. - 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
- Local mode: the broker binds to
127.0.0.1on a random port and answers only when the connection comes from127.0.0.1and theHostheader is exactly127.0.0.1:port. That blocks DNS-rebinding pages that point another name at your machine. - Tailscale mode: the
Hostheader must match--hostexactly, and theTailscale-User-Loginheader set by Tailscale Serve must match--email. - Both modes: a form post that carries an
Originfrom another site is refused.
Who can collect the key
- The link contains a random request ID. Collecting the key needs a different random token that only the runner received, compared in constant time. Having the link lets you submit, not read.
- A request accepts one submission. A second one is refused, and collecting the key deletes the request.
The form page itself
- Sent with
Cache-Control: no-store,Referrer-Policy: no-referrer, a Content Security Policy that only allows requests back to the broker, andnoindex. - The broker never logs request URLs or headers.
- Command, variable names, labels, and notes are shown as plain text. They are not secret, so never put a credential in them.
How long a request lives
- Waiting: up to five minutes from creation. Expired requests are removed on the broker's next request.
- Collected: deleted from the broker as soon as the runner claims the key.
- Cancelled: Ctrl+C on a local runner stops its broker and drops its requests. A persistent Tailscale broker keeps an abandoned request until it expires.
- Restarted: requests live only in memory, so restarting a broker discards everything waiting.
- Limits: at most 100 waiting requests per broker, 16 fields per request, and 16,384 characters per submission.
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
- A malicious agent or command. The command you approve gets the real key and can store, send, or transform it. Keyrelay isn't a sandbox. Read the command on the form.
- Other processes running as you. They can read a process's memory, and same-user tools can read its environment. Use
--stdinif the environment matters. - Memory erasure. Python can't reliably wipe strings, so collected keys are deleted, not scrubbed.
- What the target tool keeps. A CLI that logs in may write its own session or token to disk.
- Your whole Tailnet, in Tailscale mode. Any device signed in as the allowed user can open a pending link, and any process on the broker machine can reach its local port.
- Encryption at rest. Waiting keys sit in the broker's memory without extra encryption. Local mode uses plain HTTP over loopback. Tailscale mode uses HTTPS.
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.