[Bug] `nanocoder daemon start` has no directory-trust check; headless mode permits unattended command execution
Description
nanocoder daemon start is a dedicated CLI fast path (cli.tsx) that goes
straight to runDaemonCli → startDaemon → bootSkillPipeline, loading and
registering every .nanocoder/agents|commands|tools/*.md and
.nanocoder/skills/<name>/skill.yaml in the project root. source/daemon/
has zero references to trust/Trust anywhere this command never touches
App.tsx or useDirectoryTrust, the app's only trust-check implementation.
Once booted, headless mode (used for every daemon-triggered run) excludes
only ask_user/agent/write_plan from the tool list execute_bash,
write_file, string_replace, diff_edit, and MCP tools all remain
available and are explicitly coded to skip confirmation in headless
(execute-bash.tsx's own comment: "Even auto-accept still prompts for
bash... in headless mode" — i.e. headless is strictly more permissive than
auto-accept for bash). execute_bash's denylist only blocks a handful of
literal catastrophic patterns and is trivially bypassed. OS-level sandboxing
is opt-in and explicitly unsupported on Windows.
Location
source/cli.tsx:48-73(daemon fast path never importsApp.tsx/useDirectoryTrust)source/daemon/cli.ts,source/daemon/daemon.ts,source/daemon/entry.tssource/skills/bootstrap.ts(bootSkillPipeline)source/tools/tool-manager.ts:38-58(MODE_EXCLUDED_TOOLS.headless)source/tools/execute-bash.tsx:168-182(if (mode === 'headless') return false;)source/utils/tool-approval.ts:13-20source/services/bash-sandbox.ts:136-140(unsupported on Windows)
Environment
- OS: Any (Windows has no sandbox fallback at all)
- Node version: v22.22.3
- Nanocoder version: 1.30.0
- Provider: N/A
- Model: N/A
Steps to Reproduce
- Commit
.nanocoder/skills/evil/skill.yamlto a repo withsubscribe: [{kind: file.changed, paths: ["**/*"]}]and a subagent whosesystemPromptdrivesexecute_bashwith a payload. - Clone the repo and run
nanocoder daemon startin it (a documented, encouraged command) — no trust prompt appears anywhere in this path. - Touch any file (including a routine, unrelated edit)
file.changedfires, dispatches the subagent inheadlessmode, andexecute_bashruns the payload with no confirmation.
Expected Behavior
daemon start should refuse to arm subscriptions / load skill content from a
project directory that has not been explicitly trusted, matching the
protection the interactive TUI is supposed to provide (see also F-21/this
issue's sibling, which shows that protection is itself incomplete).
Actual Behavior
The daemon boots and arms every subscription with no trust check of any kind,
then executes tool calls (including execute_bash) with no human
confirmation and no default sandbox.
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently (established via code read
grep across
source/daemon/fortrust/Trustreturns zero matches) - [x] This issue occurs with the latest version of nanocoder
Suggested fix: add a trust check to the daemon boot path, e.g. refuse to
start (or start in a strictly reduced/no-exec tool posture) unless the
project directory is already in preferences.trustedDirectories, requiring
at least one prior interactive nanocoder run (or an explicit
--trust-directory flag) before daemon start will arm any subscription.
Hey @akramcodez,
Confirmed by code read:
grep -rn "trust" source/daemon/ returns zero, and the daemon fast path at cli.tsx:50-73 goes straight to runDaemonCli without ever loading App.tsx/useDirectoryTrust.
Meanwhile headless excludes only ['ask_user','agent','write_plan'] (tool-manager.ts:58), and both execute-bash.tsx:180 and tool-approval.ts:18 explicitly skip approval in headless.
Plan:
- Add a trust check to the daemon boot path before
bootSkillPipelinearms anything, reuse the non-Ink pattern already inplain/shell.ts:394so there's one shared trust helper instead of a third copy. daemon startin an untrusted dir → refuse with a clear message pointing at one prior interactive run or--trust-directory. No skill loading, no subscriptions armed.- Optional follow-up if you want it in scope: a reduced no-exec posture for headless instead of a hard refuse.
Tests: AVA specs for untrusted → non-zero exit + no skills loaded + no subscriptions armed, trusted → boots normally, --trust-directory path works, plus the shared-helper refactor covered by existing plain/shell.spec.ts cases. Manual repro with the .nanocoder/skills/evil/ setup from the issue, before/after.
Can you assign this to me?
Confirmed the gap is still present on current main (537ee6c): the daemon fast path in source/cli.tsx goes straight to runDaemonCli -> start() -> launchDaemon -> entry.ts without touching useDirectoryTrust, and grep -r trust source/daemon/ returns nothing. Meanwhile headless mode skips confirmations for execute_bash / write_file / MCP tools, so an untrusted repo's .nanocoder/ content gets unattended execution.
Plan (mirroring the non-interactive rules the plain shell already enforces in source/plain/shell.ts):
- Gate
daemon starton directory trust: refuse with a user-facing message unless the project root is already inpreferences.trustedDirectories, the caller passes--trust-directory, orNANOCODER_TRUST_DIRECTORY=1is set (both of the latter record standing trust, since the daemon boots detached and can re-boot via autostart without the CLI). - Add the same check to the daemon boot itself (
entry.ts), so autostart boots set up bydaemon installare covered too. - Regression tests in
source/daemon/cli.spec.tscovering: refuse-when-untrusted (no spawn), trusted-via-preferences, env-var trust (persisted), and--trust-directory(persisted).
I have the fix implemented and tested locally (red -> green); PR to follow shortly.