Skip to content

Nexus: ACP engine transport + Landlock engine sandbox - #35

Merged
Darknode-Official merged 1 commit into
mainfrom
feat/acp-sandbox
Nov 22, 2026
Merged

Darknode-Official merged 1 commit into
mainfrom
feat/acp-sandbox

Conversation

@Darknode-Official

Copy link
Copy Markdown
Owner

Stacked on #34 (base fix/audit-security). Merge #34 first; this PR then retargets to main.

ACP engine transport

Engines that speak the Agent Client Protocol (opencode now, and gemini when its CLI has the flag, detected from --help) run over ACP instead of a one-shot run "<prompt>":

  • Live tool cards. Edits, commands, reads and searches show up as they happen, along with streamed text, thinking and real token counts.
  • The engine asks Nexus before acting. Nexus answers from its own rules:
    • Plan mode rejects anything except read, search, think and fetch, and also switches the engine into its own plan mode.
    • /permissions deny rules and /guard apply to the engine's shell commands.
    • Guard warnings ask you in normal mode.
    • Paths outside the project ask you even in auto-accept.
  • File access stays in the project. File reads and writes the engine routes through Nexus stay in the project jail and are refused in plan mode.
  • opencode permissions. Its tools are set to ask, but any permission you configured yourself is left alone.
  • Fallback. If the handshake fails, Nexus uses the classic path for the rest of the session.
  • Setting. /acp auto|off, default auto. It is saved, and NEXUS_ACP overrides it for one launch.

Engine sandbox (Linux Landlock)

  • No root needed. It doesn't need root, setuid or user namespaces. bubblewrap won't work on Ubuntu 24.04+ because of AppArmor's userns restriction.
  • What a sandboxed engine can do. It can read the system. It can't read ~/.ssh, cloud or CLI tokens, browser profiles or shell history. Symlinks are resolved, so a link to / can't get around this. It can write only the project (not in plan mode), the temp dir and its own state dirs. Network stays open.
  • Where it applies. Claude turns, classic CLI engine turns, ACP turns, and the local agent's run_command.
  • Setting. /sandbox auto|always|off, default auto, which covers plan mode and untrusted repos. It is saved, and NEXUS_SANDBOX overrides it for one launch.
  • Fallback. Where Landlock or python3 is missing (macOS, Windows), the engine runs unsandboxed with no warning, unless you set always.
  • Known limit. A sandboxed engine can list the names of files in a denied folder, but can't read them.

Verified

  • opencode 1.17.9 over ACP, live: handshake, streaming, real usage, a real session/request_permission plus fs/write_text_file, and plan-agent selection. Checked both plain and sandboxed, and in the TUI (tool card, file count, undo #1).
  • Claude Code: runs sandboxed in plan mode.
  • Tests: test/acp-sandbox.test.js has 47 checks, using a scripted fake ACP agent plus live Landlock checks. npm test passes with a temp HOME.

Not in this PR

  • A persistent ACP session across turns. Each turn is still one process, with the conversation carried in the prompt.
  • A reverse nexus acp server.

ACP (Agent Client Protocol) for engines that speak it (opencode, gemini):
- lib/nexus/acp-client.js: zero-dep JSON-RPC/NDJSON client; streams text,
  thinking and tool calls into the TUI's tool cards; real token usage from
  the prompt result; session/cancel before any kill; falls back to the
  classic one-shot run when the handshake fails (once per session).
- The engine asks before acting (session/request_permission) and Nexus
  answers from its own rules: plan mode rejects anything but read/search/
  think/fetch (and selects the engine's own plan mode), /permissions deny
  rules and the destructive-command guard apply to execute calls, a guard
  warning asks the user in normal mode, and touching a path outside the
  project asks even in auto-accept. Client fs reads/writes stay in the
  project jail and are refused in plan mode.
- opencode tools are set to "ask" via OPENCODE_CONFIG_CONTENT, never
  overriding a permission the user configured; gemini's ACP flag is
  detected from --help.
- /acp auto|off (default auto, persisted, NEXUS_ACP).

Sandbox (Linux Landlock, unprivileged; bubblewrap is blocked by the
AppArmor userns restriction on Ubuntu 24.04+):
- lib/nexus/landlock.py: stdlib python3 launcher that restricts itself and
  execs the engine. Reads the system, never ~/.ssh, cloud/CLI tokens,
  browser profiles or shell history (symlinks resolved, so a link to / or
  $HOME cannot widen the grant); writes only the project (not in plan
  mode), the temp dir and engine state dirs. Network stays open.
- lib/nexus/sandbox.js: policy, probe, spawn wrap. Applied to claude turns,
  classic CLI engine turns, ACP turns and the local agent's run_command.
- /sandbox auto|always|off (default auto = plan mode + untrusted repos,
  persisted, NEXUS_SANDBOX). Falls back unsandboxed where Landlock or
  python3 is missing; only an explicit "always" warns about that.

Verified live: opencode 1.17.9 over ACP (handshake, streaming, a real
request_permission + fs/write_text_file, plan agent selection) plain and
sandboxed; Claude Code runs sandboxed in plan mode. Tests:
test/acp-sandbox.test.js (fake ACP agent + live Landlock checks).
@Darknode-Official
Darknode-Official changed the base branch from fix/audit-security to main November 22, 2026 23:33
@Darknode-Official
Darknode-Official merged commit b549ec2 into main Nov 22, 2026
3 checks passed
@Darknode-Official
Darknode-Official deleted the feat/acp-sandbox branch November 22, 2026 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant