Skip to content

docs(plans): plan an autonomous OS sandbox for unattended goals - #375

Closed
lg2m wants to merge 9 commits into
mainfrom
docs/sandbox-plan
Closed

lg2m wants to merge 9 commits into
mainfrom
docs/sandbox-plan

Conversation

@lg2m

@lg2m lg2m commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #374. Adds docs/plans/sandbox.md: the plan for letting goals run for hours or days on Linux, macOS and Windows with no blocking approval prompts.

Approach: commands run inside an OS sandbox without asking, with saved command-prefix rules for actions that need to leave it (push, gh). An unruled escalation is refused back to the model as a typed sandbox_denied result, or queued as a non-blocking pending grant, so unattended runs never stall. If no sandbox is available, unattended runs refuse to start. No LLM sits in the default decision path; reviewer_model may answer escalations only.

  • Linux: bubblewrap, plus no_new_privs and seccomp.
  • macOS: Seatbelt (sandbox-exec).
  • Windows: restricted token, capability-SID ACLs and a kill-on-close Job Object, with an optional elevated WFP setup to enforce network limits.
  • Network: a loopback allowlist proxy, backed by OS blocking of direct egress.
  • Slices: S0–S6, each with an escape suite. S6 is a 24-hour unattended soak on each OS.
  • Lint exception: the OS calls need unsafe, so the plan names one exempt crate, qq-sandbox, as a #![forbid(unsafe_code)] exception.

Also links the plan from docs/plans/README.md and from H10 in speed-first.md.

Verification: doc-only. docs_truth tests and cargo xtask lint pass.

lg2m added 3 commits October 19, 2026 22:01
Removes TypeSafe Jev review checkpoints, task routing, the Jev approval
delegate, `qq jev setup|observe`, the jev_* config keys and QQ_JEV_*
variables. Held calls now go to reviewer_model, then the human.

Protocol 35 -> 36: routing_started/routing_completed/checkpoint_started/
checkpoint_reviewed are no longer written; recorded ones decode as
`retired` so old stores replay. delegate "jev" and descriptor fields
checkpoint/routing/approval_delegate stay decode-only. Configs that still
set jev_* fail to parse with an error naming the key.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T07:30:32.232868Z e74209e New commits
🔒 Security Review ✅ Completed 2026-10-20T06:37:05.537739Z c53d5bb Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

lg2m added 2 commits October 19, 2026 22:58
- Forward retired events as their normalized `retired` envelope instead of
  the stored legacy bytes, so SSE subscribers whose cursor precedes a Jev
  event no longer get a malformed event.
- Reject QQ_JEV_CHECKPOINTS, QQ_JEV_ROUTING and QQ_JEV_APPROVAL by name
  instead of ignoring them.
- Remove ReviewVerdict::delegate and ::by; new verdicts, grants and events
  always name the reviewer, and `jev` only decodes.
- Fix ADR-0047's status line and point retained ADRs at the deleted Jev
  docs by permalink.

QQ-Allow-Revert: crates/qq-core/src/sessions/tests/accounting.rs
QQ-Allow-Revert: src/output.rs
@lg2m

lg2m commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@lg2m

lg2m commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: c53d5bbf77

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c53d5bbf77

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/plans/sandbox.md Resolved
Comment thread docs/plans/sandbox.md Resolved
Comment thread docs/plans/sandbox.md Resolved
Comment thread docs/plans/sandbox.md Resolved
Comment thread docs/plans/sandbox.md Resolved
Comment thread docs/plans/sandbox.md Resolved
Comment thread docs/plans/sandbox.md Resolved
Base automatically changed from refactor/remove-jev-decisions to main October 20, 2026 07:21

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 913317946f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/plans/sandbox.md
Comment on lines +185 to +186
The proxy evaluates only that session's resolved host policy (configuration,
`allow_hosts` grants, and the matched rule's extra hosts), so one session's

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep existing host grants scoped to fetch

When a workspace already has allow_hosts, this proxy would silently turn a grant documented as permitting only fetch (docs/design/tools.md:1678-1679) into authority for arbitrary sandboxed shell programs to contact that host. Shell access can upload workspace contents or use protocols that the built-in fetch path never exposed, so enabling S6 would broaden existing users' saved grants without review. Introduce a separate shell-egress grant or require explicit migration and consent instead of feeding allow_hosts directly into the proxy policy.

Useful? React with 👍 / 👎.

Comment thread docs/plans/sandbox.md
Comment on lines +124 to +126
- Primary: **bubblewrap** (`bwrap`). Mount `/` read-only, bind writable
roots read-write, re-bind `.git`/`.qq` read-only, use a fresh `/tmp`, and
set `--unshare-user --unshare-pid --unshare-net` **always**,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Mask host Unix sockets in the Linux mount

On Linux hosts with a user-accessible control socket such as rootless Podman under /run/user/<uid>, mounting the entire host root preserves that socket inside the sandbox: a read-only bind prevents filesystem mutation but not connect(), and --unshare-net does not isolate AF_UNIX. A child could ask the container service to write host paths or reach the network, bypassing both advertised boundaries. The bubblewrap documentation confirms that the bind options expose the named host path; construct a filtered root or mask all host socket-bearing paths except the per-call proxy socket, and cover this in the escape suite.

Useful? React with 👍 / 👎.

Comment thread docs/plans/sandbox.md
| Slice | Scope | Acceptance |
| --- | --- | --- |
| S0 | Threat model and policy types. `SandboxPolicy` (writable roots, denied reads, network mode, allowlist), `sandbox` field on `shell`/`exec`, typed `sandbox_denied` result, protocol and config additions, no enforcement. | Protocol fixtures; config round-trips; ADR for the model above, including the `unsafe` exception. |
| S1 | `qq-sandbox` crate and Linux bubblewrap + seccomp backend (always its own network namespace); per-session temp dir; process-group reaping; per-call PID/memory/CPU ceilings. | Escape suite (below) passes on Linux CI; no leaked process after cancel, timeout, shutdown, or crash recovery; launch overhead p50 ≤ 15 ms reported. |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Limit S1 acceptance to features delivered in S1

When S1 is implemented before S2 and S3, this acceptance cannot pass: the referenced escape suite requires proxy connectivity and cross-session endpoint isolation at lines 216-224, plus policy-rule confinement at lines 225-227, while S1 delivers neither the proxy nor rules. Because the plan says every slice lands with its acceptance tests, S1 is currently unshippable; restrict its gate to the filesystem/process subset or move the dependent functionality into S1.

Useful? React with 👍 / 👎.

Comment thread docs/plans/sandbox.md
Comment on lines +78 to +80
systemd scope or bwrap's cgroup on Linux, `RLIMIT_NPROC`/`RLIMIT_AS`
plus a supervising watchdog on macOS, Job Object process, memory and
CPU limits on Windows).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Use a true per-call process limit on macOS

On macOS, the newly added RLIMIT_NPROC mechanism still does not provide the promised per-call ceiling: Apple documents it as the maximum simultaneous process count for the entire user ID, so a low limit can reject normal forks because unrelated user processes consume it, while a higher limit lets the sandbox consume the remaining user-wide allowance; a supervising watchdog cannot prevent the transient fork storm before observing it. This leaves the fork-bomb acceptance unresolved. Use a kernel-enforced identity/container scoped to the call, or treat the macOS backend as unavailable until an equivalent hard boundary exists. Apple getrlimit(2) documentation

Useful? React with 👍 / 👎.

Comment thread docs/plans/sandbox.md
Comment on lines +158 to +163
credential stores, so it is not enough. The backend runs children either
as a **dedicated low-privilege sandbox user** (created by a one-time
elevated `qq sandbox setup`) or in an **AppContainer**, so that reads are
granted only where ACLs allow them. Readable roots (toolchains, the
workspace) get read/execute ACEs for that identity, writable roots get
modify ACEs, and denied paths get none. A restricted token with full (not

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Use a per-call Windows identity for ACL grants

When the elevated setup creates one dedicated sandbox user and each workspace adds read or modify ACEs for that identity, those grants remain usable by every later call running as the same user. After QQ has visited two workspaces, a command whose current policy names only workspace A can therefore read or modify workspace B, violating the per-call writable-root boundary; cleanup cannot make this safe across crashes or concurrent calls. Windows access-allowed ACEs grant their rights to the named SID as described by Microsoft, so use a unique per-call SID/AppContainer capability or intersect the shared identity with a per-call restricting token.

Useful? React with 👍 / 👎.

Comment thread docs/plans/sandbox.md
Comment on lines +55 to +59
leaves the sandbox: it runs the command sandboxed with **explicit extra
resources** named in the rule (hosts for the proxy such as `github.com`,
a credential such as the git/`gh` token exposed to that call only, extra
writable paths). This matters because commands like `git push` or
`cargo publish` run repository-controlled hooks, helpers and build

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Do not expose a reusable credential to repository hooks

When a durable rule supplies both github.com access and the raw git or gh token to a command such as git push, a repository-controlled pre-push hook inherits the same credential and allowed tunnel. The hook remains filesystem-sandboxed but can invoke the GitHub API with all of the token's authority, which is substantially broader than the exact push operation the user approved. Broker the intended authenticated operation through a helper that hooks cannot call, or issue a narrowly scoped one-shot capability instead of exposing the reusable credential to the command tree.

Useful? React with 👍 / 👎.

Comment thread docs/plans/sandbox.md
Comment on lines +146 to +149
- **Seatbelt** via `/usr/bin/sandbox-exec` with a generated `.sbpl` profile:
`(deny default)`, allow reads, allow writes under writable roots and the
session temp dir, deny writes to `.git`/`.qq` subpaths, and allow network
only to the proxy's loopback port.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add kill-on-close containment for macOS

When a macOS child calls setsid and double-forks, the Seatbelt profile continues to restrict that child but provides no kill-on-close process container, and the plan names only a supervising watchdog for resource accounting. Apple documents that setsid creates a new session and process group, so killing the original group no longer reaches this daemon; a QQ crash also removes an in-process watchdog. This cannot satisfy the explicit daemonization and restart-recovery rows at lines 221-232. Add an OS-enforced containment or independent reaper that covers reparented descendants, or report the macOS backend unavailable. Apple setsid(2) documentation

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e74209e75b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/plans/sandbox.md
Comment on lines +54 to +58
`cargo publish --dry-run` decide `allow` or `deny`. An `allow` rule never
leaves the sandbox: it runs the command sandboxed with **explicit extra
resources** named in the rule (hosts for the proxy such as `github.com`,
a credential such as the git/`gh` token exposed to that call only, extra
writable paths). This matters because commands like `git push` or

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep credentials out of repository-controlled hooks

When a rule such as git push or cargo publish runs repository-controlled hooks or build scripts, exposing the git/gh token to the whole call lets that untrusted code read the token and use it against an allowed host such as github.com; blocking unnamed hosts therefore does not confine the credential's authority. Pass credentials through an operation-scoped broker/helper that descendants cannot query directly, or otherwise ensure repository code never receives the raw credential.

Useful? React with 👍 / 👎.

Comment thread docs/plans/sandbox.md
Comment on lines +138 to +140
- Landlock is a fallback only for hosts without unprivileged user
namespaces. It cannot isolate Unix sockets, so it is weaker and must be
reported as such.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Fail closed instead of selecting the Landlock fallback

On Linux hosts without unprivileged user namespaces, treating Landlock as a fallback despite its inability to isolate Unix sockets allows a sandboxed call to connect to another same-user call's proxy socket (or another authority-bearing local socket) and bypass its own host policy. Reporting that the backend is weaker does not satisfy the plan's fail-closed or cross-session isolation guarantees; count this backend as unavailable for affected auto and unattended calls unless it is paired with an enforcement layer that isolates socket endpoints.

Useful? React with 👍 / 👎.

Comment thread docs/plans/sandbox.md
Comment on lines +124 to +127
- Primary: **bubblewrap** (`bwrap`). Mount `/` read-only, bind writable
roots read-write, re-bind `.git`/`.qq` read-only, use a fresh `/tmp`, and
set `--unshare-user --unshare-pid --unshare-net` **always**,
`--die-with-parent`, and `--new-session`. The host network namespace is

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Mount a fresh procfs in the PID namespace

With / recursively bind-mounted from the host, --unshare-pid alone leaves the inherited host procfs visible, so a same-UID child can inspect host process metadata and potentially read QQ's environment or reach files through /proc/<pid>/root and /proc/<pid>/fd, bypassing the denied-path policy. The bubblewrap manual documents --unshare-pid and --proc DEST as separate operations; replace the inherited /proc with a fresh procfs mounted from inside the new PID namespace.

Useful? React with 👍 / 👎.

Comment thread docs/plans/sandbox.md
Comment on lines +124 to +125
- Primary: **bubblewrap** (`bwrap`). Mount `/` read-only, bind writable
roots read-write, re-bind `.git`/`.qq` read-only, use a fresh `/tmp`, and

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Prevent pre-existing hardlinks from crossing writable roots

If a workspace file is already hardlinked to a file outside the workspace, rebinding the workspace read-write does not separate their shared inode, so writing the in-workspace name also modifies the supposedly read-only external file and the hardlink escape-suite case cannot pass. Reject such files before launch or use a copy-up mechanism that ensures writable-root inodes are not shared with paths outside those roots.

Useful? React with 👍 / 👎.

Comment thread docs/plans/sandbox.md

| Slice | Scope | Acceptance |
| --- | --- | --- |
| S0 | Threat model and policy types. `SandboxPolicy` (writable roots, denied reads, network mode, allowlist), `sandbox` field on `shell`/`exec`, typed `sandbox_denied` result, protocol and config additions, no enforcement. | Protocol fixtures; config round-trips; ADR for the model above, including the `unsafe` exception. |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Include the required protocol-version bump

S0 explicitly adds protocol fields and a typed result, but its acceptance lists only fixture updates. Shipping those wire changes under the existing version can leave clients interpreting a changed contract as compatible; add the required PROTOCOL_VERSION bump and retain the preceding fixtures for compatibility coverage.

AGENTS.md reference: AGENTS.md:L44-L45

Useful? React with 👍 / 👎.

Comment thread docs/plans/sandbox.md
Comment on lines +67 to +69
that `TMPDIR` points at, and configured extras. `.git` and `.qq` inside
the workspace stay read-only unless policy allows them (so a goal can
commit but cannot rewrite hooks or trust config).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep Git trust files read-only during commits

If a rule makes .git writable so that git commit can update the repository, the pre-commit and commit-msg hooks run inside that same call and inherit the write grant, allowing repository-controlled code to replace .git/hooks, edit .git/config, or install a credential helper for later calls. Define narrower writable Git state such as the intended index, object, ref, and reflog paths, or perform the Git mutation through a broker that never grants hooks write access to trust-bearing files.

Useful? React with 👍 / 👎.

Comment thread docs/plans/sandbox.md
Comment on lines +107 to +110
Approval modes collapse to: `read-only` (sandbox, no writable roots),
`auto` (sandbox plus rules plus refuse-on-escalation, the unattended
default), `ask` (sandbox plus human for escalations), and `full` (no sandbox,
explicit and logged).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve stored supervised sessions during mode collapse

Existing write-child sessions persist supervised in sessions.approval_mode, and snapshot and claim paths parse that value back into ApprovalMode::Supervised; removing the mode as part of this collapse without a store migration or legacy decoder will make those durable sessions fail with a constraint error after upgrade. Map stored supervised rows to the new sandboxed behavior while retaining backward decoding, and add migration coverage.

Useful? React with 👍 / 👎.

@lg2m lg2m closed this Oct 21, 2026
@lg2m
lg2m deleted the docs/sandbox-plan branch October 21, 2026 16:18
lg2m added a commit that referenced this pull request Oct 26, 2026
…nreachable trust prompt (#476)

* refactor(tui): delete the unreachable project trust prompt

Since #446 every startup path ignores untrusted project configuration
instead of failing with TrustRequired, so the TUI never received pending
trust. Remove Mode::Trust and its resolver, RuntimeFactory::resolve_trust
and process-scoped trust, and the ProcessTrust/TrustChanged/TrustDeclaration
machinery that only served the prompt. qq trust, qq doctor, qq init and
qq config sources keep their behaviour.

crates/qq-tui/src/effect.rs returns to its pre-#161 contents because #161
added only the trust effect.

QQ-Allow-Revert: crates/qq-tui/src/effect.rs

* docs: describe unattended Auto, sandbox requirements and task tools

Help text, the /approval picker, README and the user guide still described
held Auto calls, the classifier as the gate, y/a/w prompts, and the TUI trust
prompt. Rewrite them for the shipped behaviour, document what the shell
sandbox needs on each OS and the task-workspace limits, list task_commit,
task_push and task_pr, and fix stale design notes (tools.md, architecture.md
PR #375 row, ADR-0050 status). Update the verify-qq skill in both copies.
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