Skip to content

feat(chat): run commands through one sandboxed gateway, and approve similar actions once - #80

Merged
vishr merged 3 commits into
mainfrom
feat/chat-commands
Oct 29, 2026
Merged

vishr merged 3 commits into
mainfrom
feat/chat-commands

Conversation

@vishr

@vishr vishr commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

What changed

Chat can run commands again, through one Driga-owned tool, run_command, instead of Claude's Bash. Every command is parsed and classified on its argv, run in a native OS sandbox (project and scratch writable, git hooks and other later-executed paths read-only, no network), and approved on a card bound to exactly what will run. Stopping processes (kill, pkill, killall, taskkill, Stop-Process) resolves an exact process snapshot and signals only those identities. One approval can also cover similar actions: revocable 30-minute "Allow similar" grants, and burst cards with "Allow all N". Design: docs/specs/2026-10-29-chat-commands-design.md.

Why

A user asked Chat to stop 65 duplicate maestro.cli.AppKt mcp servers. Chat diagnosed it and then told the user to run pkill themselves, because 60f39c4 removed its shell: one Allow could run any command the model wrote. Separately, one cleanup took 9 approval prompts. The owner rejected both outcomes and also rejected a purpose-built tool per incident. A single gateway with a sandbox, an argv policy and an exact-target preview generalizes without reopening the hole. Native Seatbelt and bubblewrap were chosen over Anthropic's sandbox-runtime because Driga ships as one Go binary without Node.

Risk and rollout

  • Migration: 0007_chat_command_output.sql, additive (a table of command output chunks linked to Chat action messages, pruned with them). A downgrade ignores the table.
  • Agent settings: nothing new is written to ~/.claude, ~/.codex or other agent settings.
  • Text: full command output is stored only under the existing capture_text policy and retention; summaries keep head and tail.
  • Signals: yes, only for a person-approved snapshot, after re-verifying each PID's start time, owner, executable and argv immediately before signalling. Changed identities are skipped, never re-matched. Force needs a second card. Other users' processes, PID 1, process groups and Driga's own tree are refused. macOS and older Linux have a small, documented recheck-to-signal window; Linux pidfds close it where available.
  • Behaviour changes: Full auto no longer approves everything; it still asks for process and destructive commands. Chat can never auto-approve another agent's prompt. The existing kill action's force escalation now points to run_command.
  • Platforms: Windows has no sandbox yet, so only reads and process control are available there. Linux needs bubblewrap; driga doctor reports a missing sandbox.

Contract changes

  • MCP (driga mcp --chat only): new run_command tool (argv or script, cwd, timeout_seconds default 120 max 600, network). It is not exposed on the public driga mcp server.
  • Chat client API: new grant (/grant-revoke, /grant-history) and burst (/prompt-bursts, /burst-decide) routes, plus a similar field on decide and prompt-answer, all app-authenticated.
  • driga doctor: new chat_sandbox check.

Verified

  • macOS 27.0.1: go test ./..., TZ=UTC go test ./... and go test -race on chat, command, kill and web. All pass except TestPermissionHookBuiltBinary, which fails identically on main on this Mac (module-cache cleanup permission) and passes in CI.
  • Real sandbox tests with DRIGATEST_REQUIRE_SANDBOX=1: they deny writes outside the project, network, Unix sockets, protected reads and host signals, and clean up children on timeout.
  • Built-binary end-to-end TestChatCommandsBuiltBinary: a fake Claude calls pkill -f and the card lists exactly 65 spawned processes. Allow stops only those, and a 66th started after the snapshot survives. Subtests cover all outcome categories with a second force card, Deny, Stop, automatic reads, Full auto cards, replay, grants and revocation, delegated-allow containment and burst membership.
  • GOOS=linux go build ./..., go vet for native, Linux and Windows, and gofmt clean. Linux bubblewrap and native Windows process tests run in the new CI jobs.
  • UI: lint, 209 unit tests and bun run design-check (1,212 browser tests).
  • Reviewed by Codex: plan, every task, then a security review of the whole branch (5 findings) and a re-review (2 more). An automated security review after the push found 3 more. All 10 are fixed with red-before-green tests: io_uring socket bypass and a swappable seccomp file on Linux, external grants running unhardened commands, git global options and command wrappers escaping classification, writable git hooks/config, .envrc and editor hook folders inside the project, and reads outside the project skipping the card.
  • I have accepted the CLA, or will when the bot asks on my first pull request.

https://claude.ai/code/session_01T2vtcW6ihn1ywy9vxUq9a4

vishr added 3 commits October 29, 2026 13:09
…imilar actions once

Chat could diagnose problems but not act on them: a request to stop 65
duplicate maestro MCP servers ended with Chat telling the user to run
pkill. Chat lost its shell in 60f39c4 because one Allow could run any
command the model wrote. This brings commands back without that hole.

Chat gets one new tool, run_command, taking literal argv or an explicit
script. Every request is prepared, authorized, executed and recorded by
the broker, never by the model. An approval is single-use and bound to a
hash of exactly what the card showed. Commands are parsed with
mvdan.cc/sh and classified on argv as Read, Process, Other, Destructive or
Never. Wrappers that run other commands are judged by what they run, and
fail closed to a card when that cannot be determined.

Commands run in a native sandbox: Seatbelt on macOS and bubblewrap with a
sealed seccomp filter on Linux. Writes are limited to the project and a
per-conversation scratch directory, there is no network unless granted,
credential and Driga state are unreadable, and the environment is
stripped. Windows has no sandbox yet, so only reads and process control
work there.

kill, pkill, killall, taskkill and Stop-Process are a command family, not
a new tool. Driga resolves the exact process snapshot itself, shows it on
the card, re-checks each identity just before signalling, and never
re-runs a pattern match. Force needs a second card. Other users'
processes, process groups and Driga's own tree are refused.

Full auto now runs reads and sandboxed work but still asks before
process control and destructive commands. Chat can never approve another
agent's permission prompt by itself.

One approval can now cover similar actions. "Allow similar" grants are
created only by a click in the app, last at most 30 minutes, show as
"allowed by your grant" with a revoke link, and are offered to other
agents only for a short list of reads whose behaviour no environment or
config can change. Prompts from one session within 3 seconds show as one
card with "Allow all N", each item still deniable.

Command output is kept with the conversation under the existing capture
policy (migration 0007). driga doctor gains a chat_sandbox check, and CI
runs the real sandboxes on macOS and Linux and native process tests on
Windows.

Claude-Session: https://claude.ai/code/session_01T2vtcW6ihn1ywy9vxUq9a4
…utside the project

Protect Git hooks, configuration, attributes, direnv scripts and editor execution settings in project, scratch and resolved worktree metadata roots. Reserve absent paths in both sandbox backends while preserving writes to ordinary Git state. Refuse replaceable protected symlinks and Git pointers that would grant unrelated host write access.

Require read operands and the working directory to resolve inside the selected project or scratch. Keep outside and unresolved reads behind individual cards in every mode, including Full auto, and exclude them from similarity grants. Disclose worktree write roots on cards and bind grants to those roots.

Add regression tests with red evidence, generated profile and mount checks, and real sandbox tests for persistence denials and successful commits. Document the protected paths and read approval rule. Validate with native and UTC package tests, required Seatbelt integration tests, and native, Linux and Windows vet checks.

Claude-Session: https://claude.ai/code/session_01T2vtcW6ihn1ywy9vxUq9a4
…s correct on Windows

Require an explicit user namespace before disabling nested namespaces, as
bubblewrap 0.9 validates this before expanding --unshare-all. Capture bounded,
scrubbed backend stderr in probe reasons and print the result before CI tests.
Cover the namespace requirement and policy descriptor numbering with tests.

Use confined native Windows type reads and current-user SIDs in command
fixtures. Preserve outside-read approval, grant lifetimes and exact sandbox
refusals, and correct platform-specific path and socket permission fixtures.
Check Windows read handles for hard links without changing Unix boundaries.

Validated formatting, native/Linux/Windows vet, command and chat tests in the
native time zone and UTC, Windows test compilation, and targeted CLI tests.
Native Linux and Windows execution remains for CI.

Claude-Session: https://claude.ai/code/session_01T2vtcW6ihn1ywy9vxUq9a4
@vishr
vishr merged commit 9a8388b into main Oct 29, 2026
11 of 12 checks passed
@vishr
vishr deleted the feat/chat-commands branch October 29, 2026 21:56
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