35  Recipe: gate lab-mode and exp-classified tools

Field Value
Tool kailash (safety classes, lab gate)
Section Administrator
Level medium
Time ~20 min
Layer/Category admin (cross-layer)
Tags admin, safety, lab-mode, exp

35.1 Problem

Tools whose manifest row reads safety.level: exp ship in the catalogue. The class: experimental code-execution surfaces like hexstrike-ai or the kailash-mcp server face. The tools must be unreachable by default. (The pre-#210 documentation used the paired attack row as the demo name; that row was phantom-upstream and removed — kailash-os#210.) The task: demonstrate the gate actually works on the host. A bare run refuses. A half-opened gate refuses. Only the deliberate double opt-in fires the tool.

35.2 Solution

The gate is double-keyed by construction. Key 1: a host key (a NixOS option, baked into the gate wrapper at build time). Key 2: a shell key (an env var on the individual invocation). Neither key alone ever suffices:

# 1. Who is exp-gated on this host? (the gate's state record)
cat /etc/kailash/safety/wrapped-exp-tools.json
#    -> per wrapped id: {id, program, gate package}

# 2. Key 1 alone is NOT sufficient — lab host default is labMode=false:
#    the wrapper refuses (exit 126) even WITH the shell key set
KAILASH_LAB_MODE=1 hexstrike-ai --help
#    expected: refused; message names BOTH keys + cites
#    docs/responsible-use.md

# 3. Open the HOST key (deliberate, reviewable config change) and rebuild:
#    kailash.labMode = true;      # in configuration.nix / your host module
sudo nixos-rebuild switch

# 4. Still gated: the shell key is the second, in-the-moment opt-in
hexstrike-ai --help
#    expected: refused — the invocation did not set the shell key

# 5. BOTH keys on the same invocation -> the tool runs
KAILASH_LAB_MODE=1 hexstrike-ai --help
#    expected: the tool's real help output

What success looks like:

  • step 2 fails (host lab-off: the shell key alone is refused)
  • step 4 fails (host lab-on: the missing shell key is refused)
  • step 5 succeeds, and every refusal cites the responsible-use doc
  • step 1’s state file lists the wrapped tools the closure carries
  • the parity validator consumes it and independently re-parses the manifest
  • that check proves the wrapper set matches the exp row set

35.3 Discussion

  • Why double-key: a single knob is a single mistake. The host key is a deliberate configuration act (reviewable in the system declaration). The shell key is an in-the-moment, per-invocation decision. Gate state commits to the closure — a rebuild without the host key removes the gate’s open path entirely.
  • Gate data flows from the manifest, never a hand-copy: the exp-id list is scanned at eval from the declared manifest surfaces. The packaging-side generator emits the wrapper for every safety.level: exp row — the manifest row IS the routing record. The parity validator re-parses the manifest with an independent implementation and proves coverage. A deliberately broken fixture is refused (proven in CI by construction).
  • There is no separate lab-mode distro: the same image carries both postures — the gate, not the package set, is what differs. A lab-off host is the default. Opening the posture is the configuration change, and the per-invocation key stays the second.
  • Legitimate lab enablement: with authorisation (see responsible-use), open the host key on lab machines. Keep the shell key per-invocation. Prefer scoped invocations over standing open shells.
  • Requires-target is a different, lighter gate: most ATTACK tools are requires-target, not exp. They refuse to self-fire, and run freely when given an explicit target. Attack the platform, then verify walks the A-7 pairing probe sweep in a full pair run.

35.4 See also


ref: spec double-key gate (§9.2/§4.3 + tools/safety-exp-wrap.py) - verified 2026-10-14 (source: spec.md).