←Back to Blog

How an encrypted relay lets you control a local AI agent from anywhere

Nov 24, 20269 min read

AIdaemon runs on my own computer, and by design it only listens to programs running on that same computer (the local-only address 127.0.0.1:8788, called loopback). Nothing outside the machine can reach it. That's deliberate. Traffic on that local port isn't encrypted, and a signed-in app can approve terminal commands on my computer.

Local-only works fine while I'm sitting at my desk. Walk outside and try to check a running coding agent or approve a command from a phone, and you're locked out. Asking someone to buy a domain, open router ports, or install a VPN just to talk to their own agent is way too much setup.

So I wrote a Rust crate called aidaemon-remote on top of iroh and put a public relay live at relay.aidaemon.ai. Your phone finds your computer by a cryptographic key, with no tunnel, account, or domain. Here's what a relay actually is, how the connection protocol works, and how this compares to the other ways people control AI agents remotely.

What a relay is

Your laptop at home sits behind a Wi-Fi router, and your phone on mobile data sits behind your phone carrier's network. Both work like front desks that let you call out, while blocking strangers from calling straight in. Neither device has a public address the other one can dial directly. If your phone tries to reach your home computer on its own, your router drops the traffic at the door.

Both devices can make an outgoing connection to a normal server on the public internet, though. That's all relay.aidaemon.ai is. A neutral meeting point.

Instead of finding your computer by a website name or an IP address, your phone finds it by a public key. On its first run, AIdaemon creates a pair of cryptographic keys and saves them to ~/.aidaemon/remote-key with owner-only (0600) permissions. Think of the public key like a unique phone number you can share, and the private key like the secret proof that never leaves your computer. That public key becomes the daemon's permanent address, written as iroh://<endpoint-id>@relay.aidaemon.ai.

Phone                    relay.aidaemon.ai                   Daemon (at home)
| | |
| |<-- outbound connection (key) ----|
|-- dial daemon's key -------->| |
|<====== encrypted TLS 1.3 handshake forwarded via relay ========>|
| | |
|<--- 7842/udp tells each side its public address (hole punch) -->|
| | |
|<============== direct QUIC when networks allow ================>|
| (if blocked, encrypted traffic stays on relay) |

Your daemon keeps one outgoing connection open to relay.aidaemon.ai under its public key, with no account or sign-up.

When you open the app on your phone, it asks the relay for that key. The relay passes the opening messages across so both devices can set up an encrypted connection using TLS 1.3 (the same encryption behind the padlock icon in your web browser). Normally websites prove who they are with a certificate signed by an outside company. Here there's no certificate company in the middle. Your phone and your computer check each other's public keys directly.

While they talk, a discovery port on the relay (7842/udp) tells each device what its public internet address looks like from outside. Knowing those addresses, both devices send a small packet toward each other at the same time to open a direct path through their routers, a trick called hole punching. When the networks allow it, your phone and computer switch to talking straight to each other and the relay steps out of the way. When a strict office firewall or a web browser blocks that direct shortcut, the relay keeps forwarding packets.

Either way, the relay can't read a prompt, a file, or a command approval. Everything is encrypted end to end between your phone's key and your computer's key. The relay only sees public keys, IP addresses, and scrambled ciphertext.

QUIC, handshakes, and the ALPN label

Under the hood, the encrypted connection between your phone and your computer runs on QUIC. If you've never heard the name, you already use it every day. It's the modern networking protocol behind HTTP/3, which major browsers use for fast, encrypted web traffic. Older connections push everything down one single lane, so one slow file holds up everything behind it. QUIC gives you one encrypted pipe that can carry many independent lanes (called streams) at the same time.

Before any real messages flow through that pipe, the two devices do a brief introduction called the QUIC handshake. In one quick back-and-forth, they verify each other's public keys, agree on fresh encryption keys for the session, and make sure both sides expect the same kind of conversation.

That last check uses an ALPN string (short for Application-Layer Protocol Negotiation). Think of it as stating which language you speak the instant you pick up the phone. Before sending a single request, the app includes the label aidaemon/client/1 inside the QUIC handshake. If the other side doesn't speak aidaemon/client/1, the connection closes immediately without wasting another round trip.

I picked that design so I wouldn't have to invent a second API for remote devices. AIdaemon already had a local gateway built on axum (a Rust web framework), serving normal web requests and a live chat connection (a WebSocket at /client/v1/ws). Agreeing on aidaemon/client/1 tells both ends that every lane opened inside the encrypted QUIC pipe carries ordinary HTTP/1.1 web requests, including WebSocket upgrades.

If you read Rust, here's the entire server loop in crates/aidaemon-remote/src/server.rs that plugs each incoming encrypted stream straight into AIdaemon's existing web router. If you don't write code, you can skip the block and lose nothing.

async fn serve_connection(conn: Connection, peer: EndpointId, app: axum::Router) {
    let app = app.layer(axum::Extension(RemotePeer(peer)));
    while let Ok((send, recv)) = conn.accept_bi().await {
        let service = TowerToHyperService::new(app.clone());
        tokio::spawn(async move {
            let io = TokioIo::new(tokio::io::join(recv, send));
            if let Err(error) = hyper::server::conn::http1::Builder::new()
                .serve_connection(io, service)
                .with_upgrades()
                .await
            {
                debug!(%error, "Remote stream ended with an error");
            }
        });
    }
}

Two details in those fourteen lines do the heavy lifting. Calling .with_upgrades() lets live WebSocket connections work inside the QUIC stream without changing a single route handler. And attaching RemotePeer(peer) tags every incoming request with the caller's verified public key so the gateway always knows which device sent it.

Two separate locks

Recognizing which phone is calling isn't the same as letting it run shell commands. Think of it like an apartment building with a locked front entrance and a separate deadbolt on your unit. aidaemon-remote checks who you are at the front door and stops there. The gateway still decides what you're allowed to do inside.

The first lock runs during the QUIC handshake. The daemon hands iroh an Access::Only check backed by its list of paired devices. Any unknown public key gets turned away immediately with not allowed. The only time a new key can get past the front door is during the 10-minute window while you have a pairing QR code open.

The second lock is remote_router, a security guard wrapping the gateway routes for remote connections.

  • Before a device signs in, it can only reach pairing and sign-in routes. Every other request gets rejected.
  • Once a paired device proves it holds its secret signing key (a P-256 key stored on the phone), the daemon issues a 15-minute access pass (acs_...) and locks that pass to the phone's exact RemotePeer connection key.
  • The local token that works on your computer's own loopback port is always refused remotely. It never leaves the host machine.
  • Running /revoke_device drops that phone from the front door list, cancels its passes, and closes its live connections immediately.

Guessing a daemon's public key hits a closed door at the QUIC handshake. Stealing a temporary pass off a paired phone doesn't help either, because the gateway rejects any pass replayed from a different device's key.

Moving relays, browsers, and running your own

Once real devices started pairing, two practical problems showed up fast.

Early builds used n0's public relays before I launched relay.aidaemon.ai. If a phone only remembered the old relay address, moving a daemon to a new relay would've broken every paired device. So I run a tiny digital phonebook at dns.aidaemon.ai (iroh-dns-server acting as a pkarr lookup). Daemons using the project's relay post a signed note naming which relay they're currently on, and never their home IP address. Phones look up keys when dialing and never post anything themselves. If a saved relay goes quiet, the app checks dns.aidaemon.ai and still finds your computer.

The second problem was phones without the native app installed. Scanning a pairing QR code shouldn't force an app store download first. WebAssembly lets Rust code run inside a regular browser, so aidaemon-remote also compiles to WebAssembly (wasm32, using ring for encryption because aws-lc doesn't compile for the browser). I host the static web app at app.aidaemon.ai on a Cloudflare Worker. The pairing details ride after the # symbol in the link, a part browsers keep locally and never send to the website hosting the page. The browser loads the WebAssembly iroh module, connects to relay.aidaemon.ai over a WebSocket (browsers can't open raw UDP connections), and talks end-to-end encrypted to your daemon. Cloudflare only serves the static HTML and JavaScript files and never sees your messages.

Both relay.aidaemon.ai and dns.aidaemon.ai run on free-tier Linux servers (Oracle Cloud Always Free E2.1.Micro, 1 GB of memory plus a 1 GB swap file) using n0's open-source binaries, set to log warnings only (RUST_LOG=warn) and clear logs after seven days so no connection history piles up. And nobody has to use my servers. Run your own iroh-relay and add two lines to config.toml, and your daemon and phones stop talking to relay.aidaemon.ai and dns.aidaemon.ai completely.

[client_gateway.remote]
relays = ["https://relay.example.com"]

How this compares to other ways of controlling an agent

Most setups for controlling an AI agent away from your desk fall into five options. Each one trades setup effort, privacy, and convenience differently.

Comparison of remote control approaches for AI agents
ApproachSetup neededMiddleman reads trafficWorks in any browserDirect connection
Cloud-hosted agentAccountYes (the host)YesNo
Chat bot (Telegram, Slack, Discord)Bot tokenYes (chat app)Via chat appNo
Reverse tunnel (Cloudflare, ngrok)Account and domainYes (TLS ends at edge)YesNo
Mesh VPN (Tailscale, WireGuard)VPN on every deviceNoOnly on VPN devicesYes
Public-key relay (iroh)Scan a QR codeNoYes (via browser code)Yes (native apps)

Cloud-hosted agents

The easiest path if you don't want to maintain your own computer and don't need access to local files or local shell tools. The trade-off is plain. Your prompts, files, and API keys live on somebody else's servers.

Chat bots

AIdaemon started on Telegram, Slack, and Discord, and I still use them daily. The app is already on your phone and notifications work for free. The limits are privacy and interface. Telegram bot chats aren't end-to-end encrypted, so the chat company sees every message in plain text, and chat bubbles are a cramped way to read code diffs, inspect tool calls, or watch a live terminal.

Reverse tunnels

Tools like Cloudflare Tunnel and ngrok give a program on your computer a public HTTPS web address, and AIdaemon ships a tunnel manager (aidaemon-exposure) that runs them for you. Tunnels shine when you need outside webhooks or want a plain website URL without WebAssembly. You do need an account and a domain for a stable address, and the tunnel company unlocks the encryption on its own servers before forwarding traffic to your computer. Unless you add a second encryption layer yourself, the tunnel provider can read what passes through.

Mesh VPNs

Tailscale and WireGuard create a private, encrypted virtual network straight between your own devices, and they're the closest relative to what I built. Iroh's relay idea borrows directly from Tailscale's DERP relay servers. Traffic stays end-to-end encrypted, nothing sits on the public internet, and direct connections work well. AIdaemon supports Tailscale out of the box. Where VPNs get frustrating is device friction. Every phone or laptop needs the VPN installed, signed into your account, and switched on. On a work phone that blocks personal VPNs, or on a borrowed laptop, you're stuck.

Public-key relays

You trade a tiny startup delay for zero account setup and no middleman decrypting your traffic. Scan a QR code and you're connected from a phone or a browser, even behind a restrictive mobile carrier, without installing a VPN or buying a domain. It has real limits too. The first connection takes an extra beat while the relay introduces both devices. Browsers can't open direct UDP connections, so the web client always goes through the relay and downloads a WebAssembly bundle on its first visit. And you still depend on a relay server being online to make the introduction, even when you host it yourself.

AIdaemon doesn't force you to pick just one. Localhost works at your desk, aidaemon-exposure runs Tailscale or Cloudflare Tunnels when you prefer them, and aidaemon-remote stays on by default so a fresh install pairs with a phone without touching a router or handing plain text to a middleman. The crate and the scripts behind relay.aidaemon.ai are open source in the AIdaemon repository.

Stay Updated

Get the latest posts and insights delivered to your inbox.

No spam. Unsubscribe at any time.