WIP: feat: Hermes confined to act only as an Endo guest #1

Draft
dckc wants to merge 7 commits from endo-guest into main
pull from: endo-guest
Owner

Warning

Unreviewed LLM output. Generated by Claude Opus 5.5; no human has reviewed this code yet.

Hermes Agent runs as a systemd unit whose only ways out are two Unix sockets, and whose only way in, beyond them, is a read-only downloads folder:

  • host.sock: the guest's Endo methods as MCP, in the shape @endo/agent-mcp-stdio serves them;
  • llm.sock: an inference proxy that holds the API key;
  • ~/Downloads: files the host writes, at the guest's request.

The same unit runs on a Linux host, and in a vfkit microVM on macOS. CONTRIBUTING.md argues for the confinement, channel by channel.

  1. The unit (nix/hermes-guest.nix) builds on upstream's services.hermes-agent. Its sandbox is shared by every unit that runs as Hermes's user, including the bridge to llm.sock:
    • no network;
    • an empty root (NixOS confinement), with only the unit's closure, the state directory, the two sockets, and the downloads folder (read-only) bound in. So no installing software from the network; see To think over;
    • no user manager;
    • no capabilities.
  2. Linux host (nix/linux-host.nix): the host's systemd serves both sockets. The proxy is socket-activated, one instance per connection, and reads the key from its own credential. The downloads folder is the host user's, readable by Hermes's group.
  3. macOS (nix/vfkit-vm.nix, nix/darwin-host.nix): the VM has no network interface, and shares the host's store read-only, and hostDir/Downloads by virtiofs. In the VM, systemd sockets relay over vsock; on the host, launchd runs the VM and the proxy.
  4. A guide for the guest (guide/endo-guest.md), installed as Hermes's skill endo-guest, so it works whatever serves host.sock. It explains the tools as system calls and names as file descriptors, then messages, evaluate, WebApps, the downloads folder, and define.
  5. Demo (test/demo.py): unmodified Hermes as a guest, with its whole PATH from the store (.#demo-tools).
    • Host: a fake one in Python, which serves a subset of Endo's catalog with its names, schemas and answers (test/endo-catalog.json), or, with --host endo, a real Endo daemon from endo-but-for-bots' llm branch, its guest served by that package's broker (test/endo_host.mjs).
    • Model: scripted, or real, through llm-proxy.py.
    • Each run saves a transcript (runs/TASK/transcript.md), every MCP message, and what the host received.

Testing

  • Doctests pass in demo.py, fake_host.py, fake_llm.py and transcript.py.
  • The scripted demo passes on macOS against unmodified Hermes, outside any sandbox, on both hosts, in about 5 seconds each: Hermes asks for a pen, learns its methods with E(p).__getMethodNames__(), and sends it back in a reply.
  • DeepSeek V4.1 rejects Hermes's default reasoning_effort; reasoningEffort = "low" fixes that.
  • Both platforms' configurations evaluate, the downloads folder included.

Installing through the host: it works

demo.py --task install asks Hermes to install six (PyPI) and ms (npm). On macOS, Hermes runs under sandbox-exec with outbound network denied and ~/Downloads read-only. Its host grants, on request, WebApps for pypi.org, files.pythonhosted.org and registry.npmjs.org, and the downloads folder. With deepseek-flash-tee, and its whole PATH from .#demo-tools, it passed on both hosts:

  • It loaded its endo-guest skill, requested the WebApps and the folder, and narrowed the WebApps with pathjoin to the metadata, the wheel and the tarball.
  • The host wrote both files into ~/Downloads (E(d).write(name, b), with b a WebApp's blob()), so the bytes never passed through Hermes or the model.
  • It installed from there with pip install --no-index --target ~/pkgs/py and tar, checked both files' hashes against the indexes' metadata, and imported both.
  • On the fake host, it took 20 calls, 2 refused: E(app).pathjoin(p).get(), which the fake host's constrained evaluate refuses; it then split them in two.
  • On Endo, it took 41 calls. The demo host gave it the downloads folder when it asked for "a WebApp … to download the six wheel", because the host matched "download" before the URL. Hermes spent about 15 calls on that: it looked at @nets, @planes and @host, and tried E(@host).open(url), all refused, before it found the wheel through its first WebApp. Both hosts now match a URL first; a doctest covers it. This run predates that fix.

Findings:

  • Endo's mount write takes a blob, not a promise of one (its guard is M.call, not M.callWhen), so E(d).write(name, E(w).blob()) fails; the guide names the blob first. The fake host refuses a send among the args too, so it accepts nothing Endo refuses.
  • A guest's formula id must be given to the broker in full (<number>:<node>). A bare number is qualified with another node, which reaches a second incarnation of the guest, with its own mail ("Mail fraud: unrecognized parcel").
  • Each Endo daemon binds its HTTP gateway at 127.0.0.1:8920 unless told otherwise; the demo gives it port 0.
  • Toybox's fetch device answers resp.text(), so a toybox WebApp can't carry a wheel or a tarball; it needs something like blob().

Not yet checked

  • The confined units haven't been built: the closure's bind mounts are generated when the unit file is built, which needs Linux.
  • What Hermes expects under /etc (passwd, localtime, ssl/certs). Its root has no /etc; bind what it turns out to need, read-only, one file at a time.
  • Whether the bridge can join Hermes's network namespace when each unit has its own user namespace (PrivateUsers, from confinement).
  • Neither the Linux unit nor the VM has been started. This Mac has no Linux builder to build the VM.
  • Whether vfkit refuses guest connections to vsock ports it wasn't told about, and the downloads share under vfkit at all.
  • The proxy has run against a real upstream, but only under socat, not launchd or systemd.
  • define and endow with Hermes: the fake host only records definitions, and the demo's Endo host doesn't endow them.

To think over: no installing at runtime

Under confinement, Hermes sees only its closure: its shell tool and code execution run with what the unit's PATH carries. It can't install from the network, but it can install from ~/Downloads what its host fetches for it, as the install demo shows. Upstream's NixOS module offers a container mode with "full self-modification support": apt, pip and npm installs persist in a writable layer. Possible directions:

  • keep it this way: a confined guest gets new tools from whoever deploys it, through extraPackages, and packages from its host, as WebApps and the downloads folder, which the host can grant and revoke;
  • give it a writable store overlay, or a nix daemon socket, which is a much larger grant.

Not yet done

  • Toybox as the host: it doesn't serve a guest's methods as MCP yet. The demo has room for --host toybox, but no adapter from Endo's catalog to toybox's gateway, which has no request, reply or evaluate.
  • On macOS, nothing on the host listens on hostDir/host.sock yet.
  • Hermes's own flake doesn't build on macOS: its pnpm dependency hash (nix/pnpm-deps-hash) doesn't match there. The demo uses uv sync --frozen --extra mcp from a checkout instead.
  • How you talk to Hermes: its messaging gateways have no network here. Endo messages are the intended way, which Hermes would need to poll or follow.
  • Before publishing:
    • no LICENSE yet;
    • the flake's description, and mkDarwin's doc (hostDir/toybox.sock), still say toybox guest, not Endo guest;
    • the launchd labels are net.madmode.*, which suits a personal repo but not the co-op's.

Generated by Claude Opus 5.5.

🤖 Generated with Claude Code

> [!WARNING] > **Unreviewed LLM output.** Generated by Claude Opus 5.5; no human has reviewed this code yet. [Hermes Agent](https://github.com/NousResearch/hermes-agent) runs as a systemd unit whose only ways out are two Unix sockets, and whose only way in, beyond them, is a read-only downloads folder: - `host.sock`: the guest's Endo methods as MCP, in the shape [@endo/agent-mcp-stdio](https://github.com/endojs/endo-but-for-bots/tree/llm/packages/agent-mcp-stdio) serves them; - `llm.sock`: an inference proxy that holds the API key; - `~/Downloads`: files the host writes, at the guest's request. The same unit runs on a Linux host, and in a vfkit microVM on macOS. [CONTRIBUTING.md](CONTRIBUTING.md#confinement) argues for the confinement, channel by channel. 1. **The unit** ([nix/hermes-guest.nix](nix/hermes-guest.nix)) builds on upstream's `services.hermes-agent`. Its sandbox is shared by every unit that runs as Hermes's user, including the bridge to `llm.sock`: - no network; - an empty root (NixOS `confinement`), with only the unit's closure, the state directory, the two sockets, and the downloads folder (read-only) bound in. So no installing software from the network; see [To think over](#to-think-over-no-installing-at-runtime); - no user manager; - no capabilities. 2. **Linux host** ([nix/linux-host.nix](nix/linux-host.nix)): the host's systemd serves both sockets. The proxy is socket-activated, one instance per connection, and reads the key from its own credential. The downloads folder is the host user's, readable by Hermes's group. 3. **macOS** ([nix/vfkit-vm.nix](nix/vfkit-vm.nix), [nix/darwin-host.nix](nix/darwin-host.nix)): the VM has no network interface, and shares the host's store read-only, and `hostDir/Downloads` by virtiofs. In the VM, systemd sockets relay over vsock; on the host, launchd runs the VM and the proxy. 4. **A guide for the guest** ([guide/endo-guest.md](guide/endo-guest.md)), installed as Hermes's skill `endo-guest`, so it works whatever serves `host.sock`. It explains the tools as system calls and names as file descriptors, then messages, `evaluate`, WebApps, the downloads folder, and `define`. 5. **Demo** ([test/demo.py](test/demo.py)): unmodified Hermes as a guest, with its whole `PATH` from the store (`.#demo-tools`). - Host: a fake one in Python, which serves a subset of Endo's catalog with its names, schemas and answers ([test/endo-catalog.json](test/endo-catalog.json)), or, with `--host endo`, a real Endo daemon from endo-but-for-bots' `llm` branch, its guest served by that package's broker ([test/endo_host.mjs](test/endo_host.mjs)). - Model: scripted, or real, through `llm-proxy.py`. - Each run saves a transcript (`runs/TASK/transcript.md`), every MCP message, and what the host received. ## Testing - Doctests pass in `demo.py`, `fake_host.py`, `fake_llm.py` and `transcript.py`. - The scripted demo passes on macOS against unmodified Hermes, outside any sandbox, on both hosts, in about 5 seconds each: Hermes asks for a pen, learns its methods with `E(p).__getMethodNames__()`, and sends it back in a reply. - DeepSeek V4.1 rejects Hermes's default `reasoning_effort`; `reasoningEffort = "low"` fixes that. - Both platforms' configurations evaluate, the downloads folder included. ## Installing through the host: it works `demo.py --task install` asks Hermes to install `six` (PyPI) and `ms` (npm). On macOS, Hermes runs under `sandbox-exec` with outbound network denied and `~/Downloads` read-only. Its host grants, on request, WebApps for `pypi.org`, `files.pythonhosted.org` and `registry.npmjs.org`, and the downloads folder. With `deepseek-flash-tee`, and its whole `PATH` from `.#demo-tools`, it passed on both hosts: - It loaded its `endo-guest` skill, requested the WebApps and the folder, and narrowed the WebApps with `pathjoin` to the metadata, the wheel and the tarball. - The host wrote both files into `~/Downloads` (`E(d).write(name, b)`, with `b` a WebApp's `blob()`), so the bytes never passed through Hermes or the model. - It installed from there with `pip install --no-index --target ~/pkgs/py` and `tar`, checked both files' hashes against the indexes' metadata, and imported both. - On the fake host, it took 20 calls, 2 refused: `E(app).pathjoin(p).get()`, which the fake host's constrained `evaluate` refuses; it then split them in two. - On Endo, it took 41 calls. The demo host gave it the downloads folder when it asked for "a WebApp … to download the six wheel", because the host matched "download" before the URL. Hermes spent about 15 calls on that: it looked at `@nets`, `@planes` and `@host`, and tried `E(@host).open(url)`, all refused, before it found the wheel through its first WebApp. Both hosts now match a URL first; a doctest covers it. This run predates that fix. Findings: - Endo's mount `write` takes a blob, not a promise of one (its guard is `M.call`, not `M.callWhen`), so `E(d).write(name, E(w).blob())` fails; the guide names the blob first. The fake host refuses a send among the args too, so it accepts nothing Endo refuses. - A guest's formula id must be given to the broker in full (`<number>:<node>`). A bare number is qualified with another node, which reaches a second incarnation of the guest, with its own mail ("Mail fraud: unrecognized parcel"). - Each Endo daemon binds its HTTP gateway at 127.0.0.1:8920 unless told otherwise; the demo gives it port 0. - Toybox's fetch device answers `resp.text()`, so a toybox WebApp can't carry a wheel or a tarball; it needs something like `blob()`. ## Not yet checked - The confined units haven't been built: the closure's bind mounts are generated when the unit file is built, which needs Linux. - What Hermes expects under `/etc` (`passwd`, `localtime`, `ssl/certs`). Its root has no `/etc`; bind what it turns out to need, read-only, one file at a time. - Whether the bridge can join Hermes's network namespace when each unit has its own user namespace (`PrivateUsers`, from `confinement`). - Neither the Linux unit nor the VM has been started. This Mac has no Linux builder to build the VM. - Whether vfkit refuses guest connections to vsock ports it wasn't told about, and the downloads share under vfkit at all. - The proxy has run against a real upstream, but only under `socat`, not launchd or systemd. - `define` and `endow` with Hermes: the fake host only records definitions, and the demo's Endo host doesn't endow them. ## To think over: no installing at runtime Under `confinement`, Hermes sees only its closure: its shell tool and code execution run with what the unit's `PATH` carries. It can't install from the network, but it can install from `~/Downloads` what its host fetches for it, as the install demo shows. Upstream's NixOS module offers a container mode with "full self-modification support": apt, pip and npm installs persist in a writable layer. Possible directions: - keep it this way: a confined guest gets new tools from whoever deploys it, through `extraPackages`, and packages from its host, as WebApps and the downloads folder, which the host can grant and revoke; - give it a writable store overlay, or a nix daemon socket, which is a much larger grant. ## Not yet done - Toybox as the host: it doesn't serve a guest's methods as MCP yet. The demo has room for `--host toybox`, but no adapter from Endo's catalog to toybox's gateway, which has no `request`, `reply` or `evaluate`. - On macOS, nothing on the host listens on `hostDir/host.sock` yet. - Hermes's own flake doesn't build on macOS: its pnpm dependency hash (`nix/pnpm-deps-hash`) doesn't match there. The demo uses `uv sync --frozen --extra mcp` from a checkout instead. - How you talk to Hermes: its messaging gateways have no network here. Endo messages are the intended way, which Hermes would need to poll or follow. - Before publishing: - no LICENSE yet; - the flake's description, and `mkDarwin`'s doc (`hostDir/toybox.sock`), still say toybox guest, not Endo guest; - the launchd labels are `net.madmode.*`, which suits a personal repo but not the co-op's. Generated by Claude Opus 5.5. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
dckc added 7 commits 2026-11-30 05:27:41 +00:00
- The LLM bridge runs as Hermes's user but saw the host's /run. Where
  same-uid ptrace is allowed, Hermes could take it over and reach any
  socket there. It now gets Hermes's sandbox, with only llm.sock.
- A socket on a read-only mount still accepts connect(), so
  ProtectSystem=strict doesn't hide sockets under /var/lib. /var/lib is
  now empty, with the state directory bound back in.
- ProtectProc=invisible and ProcSubset=pid: other processes, and their
  command lines, are out of sight.

Generated-by: Claude Opus 5.5
How to check a change (doctests, the demo, evaluation), and a
Confinement section: the claim, why it assumes nothing about Hermes or
its config, each channel a process could use and what closes it, what
the two sockets grant, the VM's added boundary, what's not claimed, and
what has and hasn't been checked, with a probe for a running host.

Generated-by: Claude Opus 5.5
Generated-by: Claude Opus 5.5
The filesystem was the one part of the sandbox that started from the
host's view and hid places from it (/run, /var/lib, /tmp, /home), so
the argument had to assume no sockets elsewhere. Both units now start
from an empty root: their closure (fullUnit, so PATH's packages too),
/bin/sh, the state directory and the two sockets, and nothing else.
socat is added to Hermes's closure by hand, since only config.yaml
names it.

CONTRIBUTING's table now has one row for files and sockets by path,
and the "sockets the sandbox doesn't hide" caveat is gone.

Generated-by: Claude Opus 5.5
- services.hermes-guest.reasoningEffort (and mkDarwin's): DeepSeek V4.1
  takes only low, high, xhigh or max, and rejects Hermes's default.
- The README's examples use gateway.inference.coop and
  deepseek-flash-tee, its TEE-hosted DeepSeek, which supports tool
  calling.
- demo.py takes an optional MODEL and PROXY command: each connection to
  Hermes's model port is handed to PROXY as its stdin, as launchd and
  systemd hand them to llm-proxy.py, and only the outcome is checked.

Generated-by: Claude Opus 5.5
- guide/endo-guest.md, served as the MCP resource endo://guide: names
  and messages, toybox-style call, WebApps, define, and moving bytes
  over host.sock from the shell.
- The fake host gains call, define (toybox's modules-and-slots shape,
  recorded for the host) and a WebApp narrowed to one URL, with
  getBase64 for bytes, since toybox's fetch device answers text.
- demo.py --task install: with a real model, Hermes installs six and ms
  with no network but package-index WebApps its host grants; on macOS
  under sandbox-exec with outbound network denied. Checked by importing
  both from where Hermes put them.
- Temp cleanup logs, rather than fails, when Hermes's detached helpers
  are still writing.

Generated-by: Claude Opus 5.5
- the fake host serves a subset of @endo/agent-mcp-stdio's catalog,
  with its names, schemas and answers; evaluate takes only
  E(name).method(arg, ...), and __getMethodNames__
- demo.py --host endo: a real Endo daemon (endo-but-for-bots, llm),
  its guest served by the package's broker
- a downloads folder: the host writes, Hermes reads at ~/Downloads;
  BindReadOnlyPaths on Linux, a virtiofs share on macOS
- .#demo-tools: Hermes and the checks get their whole PATH from the store
- each run saves its MCP messages and a transcript
- the guide: tools as system calls, names as file descriptors;
  no Linux networking, but WebApps
- grants match a named URL before "download"

Generated-by: Claude Opus 5.5
You are not authorized to merge this pull request.
This pull request can be merged automatically.
This pull request is marked as a work in progress.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin endo-guest:endo-guest
git checkout endo-guest
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dckc/hermes-guest#1