Writing

Self-Hosted Hermes Agent on iOS: Cloudflare Tunnel + Access Service Tokens + Hermex

Moses Man · · First published on DEV Community

Running an agent on iOS sounds simple until you ask the obvious question: where does the agent actually run? Your iPhone isn't the compute — it's the client. The agent lives on your own hardware, which means your phone needs a reachable, authenticated endpoint. The easy answers all cost something: a hosted relay charges you forever, and a VPN is a heavyweight blanket when all you need is one door.

This is the setup I landed on — a Cloudflare Tunnel in front of the agent, an Access service token as the only key, and Hermex as the thin iOS client that speaks to it.

The shape

Hermes Agent runs on a small box in my homelab. cloudflared holds a persistent outbound tunnel to Cloudflare's edge, so the endpoint gets a stable hostname on my domain without opening a single inbound port — no port-forwarding, no public IP exposure, no certificate juggling. Cloudflare terminates TLS at the edge; the tunnel back to the box is already encrypted.

In front of that hostname sits a Cloudflare Access application. Instead of logins, the iOS client authenticates with a service token — a CF-Access-Client-Id / CF-Access-Client-Secret header pair scoped to exactly that one application. If the headers aren't present and valid, the request never reaches my network.

Why service tokens instead of a VPN

  • A VPN tunnels the whole device; an Access token opens exactly one route to exactly one app.
  • The token is revocable in a click, per-client, with an audit trail in the Access logs.
  • No relay middleman holding my traffic — the wire is Cloudflare edge to my tunnel, end to end.
  • It costs $0 — both the tunnel and Access live on the free tier.

Wiring it up

The tunnel is a systemd unit on the box: cloudflared tunnel run. The Access app covers the agent. hostname, with a service-token policy set to Service Auth. On the iOS side, Hermex stores the credential pair in the Keychain and attaches the two headers to every request — the fetch looks no different from any other API call.

The result: the agent is reachable from anywhere my phone has signal, nothing else on the homelab is exposed, and losing the phone means revoking one token instead of re-keying a network.

Self-hosting an agent isn't about saving $5 a month on a relay — it's about owning the whole path the request travels.

If you're building something similar, the moving pieces are small: one tunnel, one Access policy, two headers. Everything else is just your app.

All writing