AgentixOS


A safety-first control layer toward an agentic operating system on NixOS. An agent proposes a change in a sandbox, and a person applies it.

Status

Version 0.3. Open source.

RoleYearKindTry it
Concept, safety design, engineering2026AI infrastructureSource on GitHub
0commands the agent can run as root
6rungs on the safety ladder, each reversible until the next
81 + 216automated tests, in Agentix and in λ OS, which is built on it

The problem

The long-term goal is an operating system where AI agents help configure, repair, maintain and evolve the machine, without being given unrestricted control of the live system.

It starts with NixOS because NixOS gives a strong foundation: declarative configuration, reproducible builds, changes that roll back, and clear system boundaries.

What I built

  • Plan, sandbox, propose, verify. Every goal follows the same path. The work happens in a temporary Git worktree and is saved as a proposal. The source workspace stays untouched.
  • A hard stop. Agentix does not run sudo or rebuild the system. It does not edit the system configuration, commit or push. Applying, verifying and activating a change are for a person only.
  • A controller for other agents. One command prints the safety contract. Another plans a goal and, if asked, runs it end to end with a full audit. Claude Code works against the same contract.

How it is structured

The agent stops at the saved proposal. Everything after it is done by a person.

The safety ladder

controller-plan: describe what is allowed

controller-run (dry run): parse and validate, nothing runs

controller-run --execute: run the goal in a temporary worktree and save a proposal

Saved proposal patch: a person reviews the diff

A person applies the patch and verifies it

A person rebuilds and activates the new system

Each rung is reversible until the next. The agent stops after the third.

In the code

From Beach-Bum/Agentix, which is public.

controller_plan.py
controller_run.py
worktree_run.py
audit_log.py
audit_summary.py
audit_view.py

The boundary is this block, at the end of every run. It takes a second snapshot of the real workspace and compares it with the one taken before. Both ways it can go wrong end the run as a failure: if the snapshot itself cannot be taken, the workspace is treated as modified.

agentix/worktree_run.py
allowed_paths: set[str] = set()
if result["proposal_saved"]:
    try:
        allowed_paths.add(
            str(Path(result["proposal_saved"]).resolve().relative_to(path.resolve()))
        )
    except ValueError:
        pass

source_after = snapshot_source(path)
if source_after.get("error"):
    result["passed"] = False
    result["source_modified"] = True
    result["error"] = "source_snapshot_failed"
    result["source_mutations"] = [source_after["error"]]
    _audit_worktree("source_snapshot_failed")
    if json_output:
        emit_json(result)
    else:
        print()
        print("Source snapshot failed after run.")
        print(f"- {source_after['error']}")
    return 1

mutations = compare_source(source_before, source_after, allowed_new_paths=allowed_paths)
if mutations:
    result["passed"] = False
    result["source_modified"] = True
    result["error"] = "source_workspace_mutated"
    result["source_mutations"] = mutations
    _audit_worktree("source_workspace_mutated")
    if json_output:
        emit_json(result)
    else:
        print()
        print("Source workspace was mutated unexpectedly:")
        for m in mutations:
            print(f"- {m}")
    return 1

The one path a run is allowed to add is its own saved proposal, which is why that path is passed in as an exception.

What keeps it safe

  • Source untouched, checked. Every run records the state of the workspace before and after, including a hash of every untracked file. Any unexpected change fails the run.
  • A time limit. Runs stop after 1,800 seconds by default and report a timeout.
  • An audit log. One line per run, appended to a log a person can review.
  • Safe to publish. A check flags private material, and an export strips it.

How "source untouched" is checked

Before a run, Agentix records three things about the real workspace: the commit it is on, the full difference from that commit, and a SHA-256 hash of every file git does not track. After the run it records them again and compares. Any difference fails the run and is named in the result.

agentix/source_snapshot.py
def compare_source(before: dict, after: dict, allowed_new_paths: set[str] | None = None) -> list[str]:
    allowed = set(allowed_new_paths or set())
    mutations: list[str] = []

    if before.get("head") != after.get("head"):
        mutations.append(f"head changed: {before.get('head')} -> {after.get('head')}")

    if before.get("tracked_diff") != after.get("tracked_diff"):
        mutations.append("tracked files changed in source workspace")

    before_untracked = before.get("untracked", {}) or {}
    after_untracked = after.get("untracked", {}) or {}

    for rel, hash_ in sorted(after_untracked.items()):
        if rel not in before_untracked:
            if rel in allowed:
                continue
            mutations.append(f"new untracked file: {rel}")
        elif before_untracked[rel] != hash_:
            mutations.append(f"untracked file content changed: {rel}")

    for rel in sorted(before_untracked):
        if rel not in after_untracked:
            mutations.append(f"untracked file removed: {rel}")

    return mutations

The test that tries to cheat

The check is only worth something if a run that misbehaves is caught. This test stands in a fake agent that does legitimate work inside the sandbox and, in the same script, writes a file into the real workspace. The run must fail and must name the file.

tests/test_management_commands.py
def test_worktree_run_source_check_detects_source_taint(tmp_path: Path, capsys) -> None:
    from agentix.worktree_run import worktree_run

    project = tmp_path / "nixos-config"
    project.mkdir()
    create_nixos_fixture(project)

    fake_agentix = tmp_path / "fake-agentix"
    fake_agentix.write_text(
        f"""#!/usr/bin/env bash
set -euo pipefail
printf '%s\n' '# tainted source file' > "{project}/modules/tampered.nix"
printf '%s\n' '# legit worktree work' > modules/legit.nix
git add modules/legit.nix
""",
        encoding="utf-8",
    )
    fake_agentix.chmod(0o755)

    result = worktree_run(
        path=project,
        goal="create module legit with template packages",
        agentix_command=str(fake_agentix),
        save_proposal_patch=True,
        json_output=True,
    )

    output = capsys.readouterr().out
    payload = json.loads(output)

    assert result != 0
    assert payload["passed"] is False
    assert payload["source_modified"] is True
    assert payload["error"] == "source_workspace_mutated"
    assert isinstance(payload.get("source_mutations"), list)
    assert any("modules/tampered.nix" in m for m in payload["source_mutations"])
    assert (project / "modules" / "tampered.nix").exists()

A hole I found while writing this page

Reading the boundary above for this case study, I saw that two paths returned before it: a goal that fails, and a goal that times out. On those paths the result still said the workspace was untouched. That was a default value, not a finding. A run that damaged the real workspace and then failed would have been reported as a failed goal and nothing more.

The fix runs the same comparison on both paths. The error and exit code stay what they were, so nothing reading them breaks; the result gains what changed.

agentix/worktree_run.py
def _source_mutations(allowed: set[str] | None = None) -> list[str]:
    """What changed in the source workspace since the pre-run snapshot.

    Fails closed: a snapshot that cannot be taken is reported as a mutation.
    """
    after = snapshot_source(path)
    if after.get("error"):
        return [after["error"]]
    return compare_source(source_before, after, allowed_new_paths=allowed)

def _record_taint_on_failure() -> None:
    # A goal that failed or timed out may still have written to the source
    # workspace. Without this the result would say source_modified=False
    # for a run that was never checked.
    mutations = _source_mutations()
    if not mutations:
        return
    result["source_modified"] = True
    result["source_mutations"] = mutations
    if not json_output:
        print()
        print("Source workspace was mutated unexpectedly:")
        for m in mutations:
            print(f"- {m}")

The test is the earlier one with a worse agent: it writes into the real workspace and then exits with an error. It fails on the code as it was and passes with the fix.

tests/test_management_commands.py
def _tainting_agent(tmp_path: Path, project: Path, then: str) -> Path:
    """A fake agent that writes into the real workspace, then runs `then`."""
    fake_agentix = tmp_path / "fake-agentix"
    fake_agentix.write_text(
        f"""#!/usr/bin/env bash
printf '%s\n' '# tainted source file' > "{project}/modules/tampered.nix"
{then}
""",
        encoding="utf-8",
    )
    fake_agentix.chmod(0o755)
    return fake_agentix


def test_worktree_run_failed_goal_still_reports_source_taint(tmp_path: Path, capsys) -> None:
    from agentix.worktree_run import worktree_run

    project = tmp_path / "nixos-config"
    project.mkdir()
    create_nixos_fixture(project)

    result = worktree_run(
        path=project,
        goal="create module legit with template packages",
        agentix_command=str(_tainting_agent(tmp_path, project, "exit 7")),
        json_output=True,
    )
    payload = json.loads(capsys.readouterr().out)

    assert result == 7
    assert payload["passed"] is False
    assert payload["error"] == "goal_failed"
    assert payload["source_modified"] is True
    assert any("modules/tampered.nix" in m for m in payload["source_mutations"])

    events = _read_audit_events(project)
    assert events[-1]["result"] == "goal_failed"
    assert events[-1]["source_modified"] is True

This went in with pull request 1, now merged, with a second test for the timeout and a third that a clean failure still reports the workspace untouched.

The audit log

Every run appends one line of JSON to .agentix/audit.jsonl in the workspace: a UTC timestamp and what happened, with the keys sorted so two logs can be compared line by line. It is an append-only text file. Nothing chains or signs the lines, so it records what happened and does not prove nobody edited it.

How it is tested

81 automated tests, run on every push together with a syntax check of every Python file. They test the refusals as much as the features: a stale patch is refused before the person is even asked, a package change is refused on a dirty tree, and the public export leaves private files out.

What it does not do

  • There is no model inside it. A goal is matched against two patterns, "add a package" and "create a module". Agentix is the harness an agent such as Claude Code works through, not an agent that reasons.
  • Ignored files are not hashed. A change to a file git ignores is not seen.

The policy check is a list of eight text patterns (sudo, rm -rf, SSH keys, /etc/nixos, and network fetches as a warning). It catches the obvious request; it is not a sandbox, and a determined command could be written to slip past it. The actual boundary is elsewhere: the agent works in a temporary copy, the real workspace is checked before and after, and only a person applies a patch or rebuilds the system.

It is about 3,900 lines of Python 3.12 at version 0.3, with no third-party dependencies: only the standard library, git and Nix. It has been used on my own machines, not at scale.

In use

λ OS is built on Agentix and is public. It manages the lifecycle of the 55 modules in a Logos workspace: it takes a snapshot, tests each module in a sandbox on a timer, rolls a failing module back to its last good version, orders upgrades by their dependency graph, and proposes changes for a person to approve.

Its audit log, and what "tamper-evident" has to mean

λ OS seals its audit log: for every line it records a hash of the line, the hash of the line before, and a root binding both to a position. The design documents call the log tamper-evident.

Checking that claim for this page, I found it was not true yet. The verifier recomputed every hash and compared them with nothing. A rewritten event verified as valid. This is the part that now does the comparing:

agentix_logos/audit_chain.py
records = load_chain_sidecar(sidecar_path)
errors.extend(_check_sidecar(records))

mismatched = [
    i for i, rec in enumerate(records[: len(lines)])
    if compute_cid(lines[i]) != rec.get("cid")
]
for i in mismatched[:MAX_REPORTED_ERRORS]:
    errors.append(f"Line {i}: content does not match the CID sealed for this position")
if len(mismatched) > MAX_REPORTED_ERRORS:
    errors.append(
        f"{len(mismatched) - MAX_REPORTED_ERRORS} more lines do not match "
        f"(first divergence at line {mismatched[0]})"
    )

if len(lines) < len(records):
    errors.append(
        f"Log is shorter than its sealed chain: {len(records) - len(lines)} sealed "
        f"line(s) missing from the end"
    )

return ChainVerification(
    valid=not errors,
    entries=len(lines),
    errors=errors,
    sealed=min(len(lines), len(records)),
    unsealed=max(0, len(lines) - len(records)),
)

And one of sixteen tests that tamper with a sealed log. This is the careful attacker, who changes an event and then corrects the hash recorded for it:

tests/test_audit_tamper.py
def test_editing_the_sidecar_to_match_a_changed_line_is_detected(sealed: Path) -> None:
    # the careful attacker: change the event, then fix up its recorded CID
    from agentix_logos.audit_chain import compute_cid

    lines = _lines(sealed)
    lines[2] = lines[2].replace("false", "true ")
    _rewrite(sealed, lines)

    sidecar = sealed.parent / SIDECAR_NAME
    records = [json.loads(r) for r in sidecar.read_text(encoding="utf-8").splitlines()]
    records[2]["cid"] = compute_cid(lines[2])
    sidecar.write_text("".join(json.dumps(r, sort_keys=True) + "\n" for r in records), encoding="utf-8")

    result = verify_chain(sealed)
    assert result.valid is False
    # entry 2's root no longer matches its fields, and entry 3 no longer links to it
    assert any(e.startswith("Chain entry 2:") for e in result.errors)
    assert any(e.startswith("Chain entry 3:") for e in result.errors)

The others rewrite an event in place, change one character on each line in turn, delete, insert, reorder, and cut the log short. All sixteen passed as valid before the change. The fix is pull request 1, now merged; 216 tests pass.

What it still cannot do, and the code says so: someone who can rewrite the log can rewrite the sealed record beside it and recompute everything. The check only binds once that record is held somewhere the writer cannot reach. That publishing step is designed and not built.

More

Project notes on the weblog
Open ↗
Agentix and Logos, the essay
Open ↗
λ OS, built on Agentix
Open ↗