Skip to content

Credential brokering

Run an AI agent or any program under maruhi proxy run so it holds placeholders instead of secrets — the real values are written into requests only at a local proxy, only toward the hosts you allow, and short-lived tokens are minted on your machine from credentials the program never sees.

maruhi run -- <command> keeps values off the disk, but the program it starts holds them in its environment and can print them. For a coding agent that is the whole problem: an agent that runs your program reads its output, and a single env or a crash dump puts the values into its transcript. maruhi proxy run -- <command> closes that gap for every value a request carries over HTTPS:

  • The program receives a placeholder for each brokered variable (mhp_GITHUB_TOKEN_…, random per run). It cannot print, log, or send a value it never had.
  • Its HTTPS traffic goes through a proxy on your machine, started and stopped with the command. For the hosts a rule names, the proxy terminates TLS with a certificate authority created for this run, writes the real value in place of the placeholder, and forwards the request. Every other host is tunnelled untouched, with the program’s own end-to-end TLS.
  • A placeholder used toward another host the proxy inspects, or in a part of the request the rule does not allow, is refused with a message that names the variable and the rule, and the request is not sent. Toward a host no rule names, the connection is a tunnel the proxy does not look into: the placeholder travels as it is, nothing is substituted, and the host rejects it.
  • A value the API echoes back is replaced by the placeholder in the response (body and headers; a compressed response is decompressed first, and one in an encoding the proxy cannot read is refused rather than forwarded unchecked), so it does not reach the program that way either.
  • With a connector, the value written into the request is not a long-lived key but a token minted on your machine just in time — a GitHub App installation token, valid for an hour, from an App key the program never sees.

The maruhi server is not involved and sees none of it. Under end-to-end encryption your values are decrypted on your machine, and with brokering they stay there: neither the server nor the agent holds the plaintext.

Set up

  1. Add maruhi.proxy.json to the repository root. It names variables and hosts, never values, so it is committed like any other config file:

    {
      "version": 1,
      "variables": {
        "GITHUB_TOKEN": ["api.github.com", "github.com", "*.githubusercontent.com"],
        "OPENAI_API_KEY": { "mode": "broker", "hosts": ["api.openai.com"] },
        "DATABASE_URL": "passthrough",
        "LOG_LEVEL": "passthrough"
      }
    }
  2. Start the agent (or any program) under it:

    maruhi proxy run --env dev -- claude

    Before the command starts, proxy run prints what the program will get: which variables are brokered and toward which hosts, which are passed through with their real value, and which are withheld.

    With the file in place, plain maruhi run -- <command> does the same thing. The repository’s config decides what a child receives, so an agent that runs maruhi run itself, or a script that already does, gets the brokering without being told. The file is applied only once you have accepted it on your machine: run maruhi proxy accept yourself, from your terminal (not inside an agent, not through a pipe). It prints the rules it is accepting and records the file’s content under your account’s home (~/.config/maruhi/proxy-accepted.json — the home the system user database gives; MARUHI_CONFIG_DIR and XDG_CONFIG_HOME do not move this file, so an environment variable cannot point maruhi at a record an agent wrote), and marks the project as brokered on your machine; the acceptance is per project, so a file accepted for one project is not applied to another until you accept it for that one too. From then on anyone on the machine, an agent included, runs under those rules. A file that is new or has changed since is refused everywhere — with a message naming maruhi proxy accept — so an agent cannot rewrite the rules (pass everything through, add a host of its own) and apply them itself, and your next ordinary maruhi run does not accept its change by the way. Deleting the file, or running from another directory, does not help it either: once a project has been brokered on your machine, plain maruhi run without the config injects the real values only for a person at a terminal. To inject the real values instead — the only shape that hands a program the plaintext — run maruhi run --plain -- <command>, which is allowed only to a person at an interactive terminal (an agent, a pipe, a redirect, or CI is refused). Without a maruhi.proxy.json in the working directory, maruhi run injects the real values as it always has. When the command exits it prints how many requests were brokered, tunnelled, blocked, or failed. Add --verbose for one line per request (method, host, path, and the variable names substituted — never a value).

Inside, curl -H "Authorization: Bearer $GITHUB_TOKEN" https://api.github.com/user works, git push to GitHub over HTTPS works, and echo $GITHUB_TOKEN prints mhp_GITHUB_TOKEN_….

The config file

Key Meaning
version Always 1.
project Optional. The project ID this config belongs to; proxy run uses it instead of defaultProject, and refuses a --project flag that names a different project.
unmatched What happens to hosts no rule names: "allow" (default — tunnelled untouched, never inspected) or "block" (the connection is refused). block turns the proxy into an egress allow-list for the program.
unlisted What happens to variables no rule names: "withhold" (default — not injected; the program does not get them) or "passthrough" (injected with their real value, as maruhi run would).
variables One rule per environment variable the program sees. The key is the variable name; the value is a rule.

Rules:

Rule What the program gets
["host", …] or { "mode": "broker", "hosts": […], "surfaces"?: […], "placeholder"?: "…" } A placeholder. The real value is substituted only toward hosts, only on the listed surfaces.
{ "mode": "connector", "connector": "github-app", "inputs": {…}, "hosts": […], … } A placeholder for a token the proxy mints from the variables named in inputs. Those variables are consumed by the proxy and never injected. See Short-lived tokens.
"passthrough" The real value, as under maruhi run. For values a proxy cannot substitute: a database URL used over the Postgres protocol, a key the program needs locally, a non-secret setting.
"withhold" Nothing. The variable is not injected.

A host is host[:port], HTTPS unless written http://host[:port]. *.example.com matches one or more labels under example.com (not example.com itself). The default ports are 443 and 80. An IPv4 address is accepted. Plain http:// is accepted only for the loopback (localhost, *.localhost, 127.0.0.0/8) — "http://localhost:8787" brokers toward a local development server, and that is the only way a value ever travels unencrypted; a rule naming any other host over plain HTTP is refused when the config is read.

Surfaces are the parts of a request a placeholder is substituted in: header (the default and usually all you need — Authorization, X-Api-Key, and a Basic credential, which is decoded, substituted, and re-encoded), query (?key=…), path, and body. The default is headers only on purpose: a value substituted into a body that the API stores — an issue comment, a gist, a chat message — would be published by that API. Add "surfaces": ["header", "body"] for an API that takes the credential in the body (an OAuth token endpoint, for example), and keep the rule’s hosts to that API.

A placeholder is random per run (mhp_<NAME>_<22 random characters>). Some clients validate a credential’s format before sending it; for those, set "placeholder" to a fixed string of the right shape (16 to 256 printable characters). Placeholders must be unique across rules, and one may not contain another. A value substituted into the path or query is percent-encoded; one substituted into a header must be a single Latin-1 line, or the request is refused with a message naming the variable; one substituted into a body is written as it is.

Short-lived tokens (connectors)

A connector turns a long-lived credential into a short-lived one at the moment of use, on your machine. The first connector is github-app:

{
  "version": 1,
  "variables": {
    "GITHUB_TOKEN": {
      "mode": "connector",
      "connector": "github-app",
      "inputs": {
        "appId": "GH_APP_ID",
        "privateKey": "GH_APP_PRIVATE_KEY",
        "installationId": "GH_APP_INSTALLATION_ID"
      },
      "hosts": ["api.github.com", "github.com"]
    }
  }
}

GH_APP_ID, GH_APP_PRIVATE_KEY (the PEM file GitHub gives you when you generate a key for the App), and GH_APP_INSTALLATION_ID are ordinary maruhi variables. The program sees GITHUB_TOKEN as a placeholder and nothing of the three inputs. On the first request toward a listed host that uses the placeholder, the proxy signs a short JWT with the App key, asks GitHub for an installation access token (valid for one hour), and writes that token into the request. It re-mints five minutes before expiry, and when the command ends it revokes the tokens it minted, so the credential’s life is the run’s. If GitHub refuses, the request is answered with 502 and GitHub’s message; nothing is sent to the host.

Compared with a personal access token in GITHUB_TOKEN: the credential that exists for an hour has exactly the App’s permissions on exactly its installation, and the key that could mint more never leaves the proxy’s memory. The maruhi server sees neither.

What the program sees

  • Its environment: placeholders for brokered variables, real values for pass-through ones, and the variables that point its HTTP clients at the proxy and make them trust the run’s CA — HTTPS_PROXY / HTTP_PROXY (and lower-case; the URL carries a credential for this run, http://maruhi:<random>@127.0.0.1:<port>, which every common client sends as Proxy-Authorization), an empty NO_PROXY, SSL_CERT_FILE, REQUESTS_CA_BUNDLE, CURL_CA_BUNDLE, GIT_SSL_CAINFO, AWS_CA_BUNDLE, PIP_CERT, CARGO_HTTP_CAINFO, NIX_SSL_CERT_FILE, GRPC_DEFAULT_SSL_ROOTS_FILE_PATH (the runtime’s bundled Mozilla roots plus, where the runtime exposes them, the operating system’s roots, plus the run’s CA), NODE_EXTRA_CA_CERTS and DENO_CERT (the CA), and NODE_USE_ENV_PROXY=1 (Node 24’s fetch honours the proxy variables only when asked). These are written after the variables, so a variable of the same name cannot redirect the traffic.
  • Two files in a private temp directory for the command’s lifetime: the CA certificate (public) and the bundle of roots plus that certificate. The CA’s key exists only in the proxy’s memory; the leaf certificates are issued per host and die with the process. Nothing else is written, and the directory is removed when the command ends.
  • On a refused request, a plain-text answer such as maruhi proxy: the placeholder for GITHUB_TOKEN is only substituted toward the hosts its rule names (this request is for api.example.com:443); the request was not sent — so an agent learns why and can tell you.

Verified on Linux: curl and Bun (fetch) through the proxy with the run’s CA; curl, git, Python (urllib), Node (fetch with NODE_USE_ENV_PROXY), and Bun sending the proxy credential from the URL. Expected to work from their documented behaviour, not verified here: Python requests / httpx, Ruby, Deno, Go and the GitHub CLI on Linux (Go reads SSL_CERT_FILE on Linux only, not on macOS, where a Go program such as gh would refuse the run’s CA). Java needs its own -Dhttps.proxyHost flags and trust store. A program that ignores these variables simply does not go through the proxy: it sends the placeholder to the host and gets an authentication error, and nothing leaks.

Running the agent in a sandbox (the guarantee)

On your workstation the agent runs as you, with your keychain. Everything above makes the safe path the default, but a program that is determined to misbehave still has your session: maruhi run --plain is refused to it, yet the refusal rests on detecting an agent, and a same-user process can in principle read any other process of yours. The structural guarantee is to run the agent where it has no maruhi credential at all — a container, a devcontainer, a separate OS user — and make the host’s proxy its only path to the values. Then there is no maruhi to run inside: the sandbox holds placeholders and nothing else.

proxy run supports this directly: --listen binds the proxy to an address the sandbox can reach, and --advertise is the name the sandbox knows the host by. Every request still needs the run’s proxy credential, which only the command’s environment carries. With Docker Desktop, for example:

maruhi proxy run --env dev --listen 0.0.0.0 --advertise host.docker.internal -- sh -c '
  docker run --rm -it \
    -e HTTPS_PROXY -e HTTP_PROXY -e NO_PROXY -e NODE_USE_ENV_PROXY \
    -e GITHUB_TOKEN -e OPENAI_API_KEY \
    -v "$SSL_CERT_FILE:/etc/maruhi/ca-bundle.pem:ro" \
    -e SSL_CERT_FILE=/etc/maruhi/ca-bundle.pem -e REQUESTS_CA_BUNDLE=/etc/maruhi/ca-bundle.pem \
    -e CURL_CA_BUNDLE=/etc/maruhi/ca-bundle.pem -e GIT_SSL_CAINFO=/etc/maruhi/ca-bundle.pem \
    -e NODE_EXTRA_CA_CERTS=/etc/maruhi/ca-bundle.pem \
    my-agent-image claude'

The shell inside proxy run expands $SSL_CERT_FILE to the host path of the run’s CA bundle, so the container mounts it and points its own variables at the mount. HTTPS_PROXY carries the credential and the advertised address. Nothing of your keychain, your token, or a real brokered value enters the container; a passthrough variable you list with -e does. Because the proxy runs on the host, in sandbox mode it refuses destinations on the host itself that no rule names — the loopback, link-local addresses (where most clouds’ metadata service lives), the shared address space 100.64/10 (Alibaba Cloud’s), the IETF protocol-assignment block 192.0.0.0/24 (Oracle Cloud’s), Azure’s wire server 168.63.129.16, the AWS IPv6 metadata address, any textual form of those, and names that resolve to them; a name it clears is connected by the address it checked, not resolved a second time — so the sandbox cannot use it to reach a service the container was built to keep it from; a rule naming http://localhost:8787 is your decision and still works. An IPv6 address for --listen or --advertise is written in brackets ([::1]:8080). On Linux, --network host with the default loopback binding works as well. The same shape applies to a devcontainer or a remote host: bind the proxy where the sandbox can reach it, advertise the name it uses, and copy the CA bundle in.

Limits

  • The variables are advisory inside one user account. A program (or an agent) can unset HTTPS_PROXY and connect directly — it then sends the placeholder and fails, which is the safe outcome; it still cannot obtain a brokered value. What it can do is attempt maruhi run --plain with your session, rewrite or delete maruhi.proxy.json, or run from another directory; all of these are refused unless a person is at the terminal (a rewritten file needs maruhi proxy accept), but the refusal relies on detecting the agent, which can fail for an unknown agent on a pseudo-terminal, and the acceptance record is a file your user can write. For a guarantee, use the sandbox shape above.
  • Not substituted: a placeholder transformed by the client before sending — base64 outside a Basic header, a hash, a signature. Signature schemes that sign with the credential (AWS SigV4) cannot be brokered this way; use the cloud’s federation (OIDC → STS) instead, and pass through what remains. A credential whose format the client parses as a JWT is likewise not supported.
  • Only HTTP and HTTPS. A Postgres connection string or an SSH key is used over its own protocol; declare it passthrough and rely on the run-output redaction below.
  • Brokered hosts are intercepted, so a client that pins its certificate for such a host, or needs mutual TLS to it, fails. HTTPS hosts no rule names are tunnelled and not intercepted. Plain HTTP toward a host no rule names is relayed through the same inspection path (its body is read, up to 32 MiB; an upgrade is refused), with nothing substituted; the summary counts it as relayed. WebSocket upgrades toward a brokered host are refused; request bodies over 32 MiB toward a brokered host are refused (send uploads to a host no rule names). HTTP/2 is negotiated down to HTTP/1.1 on brokered hosts. A CONNECT to an IPv6 literal is refused.
  • The proxy itself does not use an upstream proxy. Behind a corporate proxy, the run’s proxy reaches the hosts directly.
  • The proxy’s port is on the loopback for the command’s lifetime, and every request must carry the run’s proxy credential (the userinfo of HTTPS_PROXY), so another local process cannot use it without reading the program’s environment. The plaintext handlers behind the TLS termination are Unix sockets inside the run’s private directory (mode 0700), not ports. A placeholder is a capability for that one run and is visible to whatever the program shows it to.

Review changes to maruhi.proxy.json the way you review a CI workflow: it decides which host receives which value.

Output redaction (maruhi run and proxy run)

Pass-through values still enter the program, and maruhi run injects every value. When the output of such a program may land somewhere other than your terminal, maruhi scrubs it: the program’s stdout and stderr are relayed through the CLI and every injected value — whole, line by line, and in its JSON-escaped form — is replaced by [redacted], byte for byte, as it streams. It triggers when a known AI agent is detected, or when stdout or stderr is not a terminal (a pipe, a redirect, CI). Running maruhi run yourself in a terminal that no agent host controls changes nothing: the program keeps the terminal.

It is exact-match, so it catches maruhi run -- env, a config dump, a stack trace with the environment in it — and not a value the program transformed (base64, a hash, another encoding). The proxy’s response scrub follows the same rule, and also knows the two forms the proxy itself puts on the wire: a value percent-encoded into a path or query, and a Basic credential it re-encoded. Values and lines shorter than 8 bytes are not redacted: PORT=3000, DEBUG=1, a { line of a JSON value are ordinary text that would otherwise be rewritten wherever it appears in the output (a secret that short is not protecting anything either). Binary output is left alone unless it contains a value of 8 bytes or more. While it is active the program’s stdout and stderr are pipes, not the terminal: an interactive program loses colours and terminal detection, and maruhi run itself runs under a detected agent host (Claude Code, Cursor, …) even when you type it at that host’s terminal. When the program exits, output a background process it left behind still writes stops being relayed after half a second. Treat it as a second line of defence; keeping values away from the program is what proxy run is for.

© 2026 maruhi contributors

Type to search…

↑↓ navigate↵ selectEsc close