One fixed session, born once, kept and compacted forever. The daemon wakes on its own impulse, works on a persistent goal, detects repeated failures, reflects, changes approach, and records everything. It starts as root, builds a debootstrap chroot, then drops to an unprivileged uid and applies Landlock and seccomp. Dashboard, HTTP API and MCP expose the same snapshot; the event log is root-owned and append-only. Offline suites cover the engine, the daemon, both sandbox layers and the dashboard/MCP sockets; a root-only script covers debootstrap, chroot, uid drop and plugin loading.
5.5 KiB
krang
An autonomous agent daemon built on the splinter engine. The design notes and the prior art are in docs/DESIGN.md.
krang exists to test one hypothesis: what an assistant lacks is not intelligence but a regular impulse to continue. It is born once, keeps one session forever, wakes on its own cadence, works on a goal, notices when it is stuck, changes approach, and records what happened. There is no user to ask.
It lives in a chroot. The process starts as root only to build that world, then drops to an unprivileged uid and applies two one-way restrictions: Landlock for paths and seccomp-bpf for syscalls on Linux (the design is pledge/unveil; the OpenBSD backend is not implemented yet).
Build
make -C ../splinter # libsplinter.so and the headers
make
make check # no network, no key, no model
libsplinter.so has no SONAME; the binary carries an rpath to ../splinter.
Rebuild krang whenever splinter changes.
Configure
sudo install -d /etc/krang
sudo install -m 0600 krang.conf.example /etc/krang/krang.conf
$EDITOR /etc/krang/krang.conf
The goal is used only when the session is empty: that is the newborn. After
that the goal in the session's .meta is the life's goal.
Prepare and start
sudo krang --prepare-rootfs --config /etc/krang/krang.conf
krang --plan --config /etc/krang/krang.conf # read the plan, do not start
sudo krang --config /etc/krang/krang.conf # start
Do not start it casually: once it has a provider it will act on its own. The
service unit in share/krang.service restarts it after an unexpected exit; a
deliberate stop is systemctl stop krang (or SIGTERM).
What it offers
- Dashboard
http://127.0.0.1:8096/— state, goal, impulses, turns, tool calls, failures, tokens, cost, context, session, compactions, stuck level, last outcome and error, working notes, and a chat box. - HTTP API —
/healthz,/api/state,/api/impulses,/api/log,/api/history,/api/threads,/api/tools,/api/sandbox,/api/config,/api/events,POST /api/say,GET /api/say/<id>,POST /mcp. - MCP — newline-delimited JSON-RPC on
127.0.0.1:8098. Tools:krang_state,krang_impulses,krang_events,krang_session,krang_history,krang_tools,krang_sandbox,krang_config,krang_say,krang_say_status,krang_steer,krang_cancel. Nokrang_approve: krang never asks. - Chat from either surface goes into the same session as the daemon's own impulses. One turn at a time; a message that arrives mid-turn is queued.
The model also gets journal_search (read-only): it searches the full session
log, including the history compaction dropped.
Splinter plugins are opt-in: plugin = /absolute/plugin.so (max 8). The root
phase bind-mounts each plugin and libsplinter.so read-only into /opt/krang
and sets LD_LIBRARY_PATH; only the path is wired, not the plugin's own
plugin NAME { } config block yet. The root integration loads the clock plugin
inside the chroot as a proof.
If a token is set in the config, loopback is not required and every request
needs it (Authorization: Bearer, ?token=, or the MCP AUTH <token> line).
Without a token krang refuses to bind to a non-loopback address.
The experiment log
state/sessions/krang.jsonlis the conversation and the model's memory.state/events.jsonlis the append-only experiment log. It is opened by the root phase, owned by root, mode 0600, and written through the inherited descriptor; the sandbox user can neither open nor truncate it. The fd isFD_CLOEXEC, so theruntool's children do not inherit it.- The dashboard, HTTP API and MCP all read the same snapshot and the same ring of recent events. There is no second counter.
Tests
make check
make check-asan
./krang --check --config krang.conf.example # config + one scripted turn
./krang --self-test # one scripted turn, no network
sudo tests/root-integration.sh # debootstrap + chroot + drop
make check covers config parsing, the birth prompt, stuck detection, the
snapshot/HTTP/MCP surfaces, a real scripted engine turn, the engine under
Landlock + seccomp, and kdaemon_run itself (one birth impulse on the script
transport, then a clean stop). The sandbox tests prove Landlock denies a write
outside the allowed set and seccomp denies mount(2) while
fork/execve/network still work.
tests/root-integration.sh is the root-only proof: it prepares a real rootfs
with debootstrap, enters it with --sandbox-test, loads the clock plugin from
the splinter tree, and checks uid 65534, mount denial, plugin execution,
event-log ownership/mode, session ownership, and that the sandbox uid cannot
read the event log. It never starts the autonomous daemon or calls a provider.
Safety notes
- chroot is isolation, not a jail against root. krang runs as an unprivileged uid after setup and has no path back.
- The provider key is readable by the daemon; assume the model can eventually
see anything in its environment. Use a throwaway, budget-capped key. The
runtool's environment is filtered withsp_secret_env_add(), and the event log redacts the configured key. - The network namespace is shared.
runcan reach the network; the chroot does not change that. - The session log is the model's memory. It is writable by the sandbox uid; the experiment log is not.
- User namespaces and kernel bugs remain outside the model. The layers raise the cost of an escape; they are not a proof.