Skip to content

Feat/runtime permission profile sandbox - #880

Closed
YayoiNanoka wants to merge 47 commits into
apache:mainfrom
YayoiNanoka:feat/runtime-permission-profile-sandbox
Closed

YayoiNanoka wants to merge 47 commits into
apache:mainfrom
YayoiNanoka:feat/runtime-permission-profile-sandbox

Conversation

@YayoiNanoka

Copy link
Copy Markdown
Contributor

Related issue

Related to #509.

Summary

This PR introduces the Codex-style permission management and sandbox enforcement architecture for Maka's local macOS runtime.

It replaces the previous worktree/write-back direction with:

  • a platform-independent PermissionProfile
  • runtime sandbox capability checks
  • macOS Seatbelt enforcement
  • sandboxed command and filesystem execution
  • one-shot additional permissions
  • explicit, approved unsandboxed execution

Workspace writes are applied directly to the real workspace. This PR does not introduce worktrees, diff/write-back, or an apply-patch UI.

What changed

Permission model

  • Add managed, disabled, and external permission profiles.
  • Compile existing modes into active profiles:
    • explore -> read-only
    • ask / execute -> workspace-write
    • bypass -> danger-full-access
  • Protect .git, .agents, and .codex metadata by default.
  • Keep approval policy separate from filesystem/network policy.

macOS sandbox enforcement

  • Add SandboxManager and the macOS Seatbelt backend.
  • Execute foreground and background Bash through sandbox wrapper argv.
  • Preserve streaming, timeout, abort, bounded output, and process-tree termination.
  • Fail closed when required sandbox capabilities are unavailable.
  • Do not silently fall back to host execution.

Filesystem tools

  • Run Read, Write, Edit, Glob, and Grep inside a one-shot sandboxed filesystem worker.
  • Preserve realpath containment, symlink escape protection, write locks, and Edit matching.
  • Apply the same effective profile in the runtime matcher, worker, and Seatbelt policy.
  • Normalize macOS /tmp and /private/tmp aliases consistently.

Additional permissions

  • Support exact and subtree filesystem permissions for one tool call.
  • Support one-command network enablement.
  • Bind grants to the session, turn, tool call, intent, path, and permission hash.
  • Revalidate paths before execution and prevent grant replay or reuse.
  • Route ask requests to the user and execute requests to a no-tools AutoReviewer.

Explicit unsandboxed execution

  • Add Bash require_escalated requests.
  • Require an exact one-shot grant before disabling the sandbox.
  • Support foreground and background Bash.
  • Never automatically replay a sandbox-denied command.
  • Block repeated AutoReview attempts for the same command/cwd in one turn after denial or reviewer failure.

Runtime integration and diagnostics

  • Use permission-aware tool assembly in desktop, CLI, and child agents.
  • Represent headless/isolated runtimes with PermissionProfile.External.
  • Add sandbox capability snapshots to model context.
  • Add safe RunTrace events for sandbox resolution, approvals, denials, and failures.
  • Avoid persisting raw commands, environment variables, granted paths, or credentials.

Security properties

  • Sandbox-required execution fails closed.
  • Tool arguments cannot directly disable the sandbox.
  • Additional and unsandboxed grants are runtime-owned and single-use.
  • Protected metadata remains denied unless an exact permission is approved.
  • Filesystem workers receive only the capability required for the current operation.
  • AutoReviewer failure, timeout, invalid output, or denial never results in host execution.

Out of scope

  • Linux sandbox backend
  • Windows sandbox backend
  • worktree or workspace-copy lifecycle
  • diff/write-back
  • apply-patch UI
  • permanent prefix rules
  • AutoReview-denial human override
  • managed domain/method-level network policy
  • remote/external escalation protocol

Verification

Completed locally on macOS:

  • npm test
  • npm run typecheck
  • npm run build
  • Runtime tests: 1135/1135 passed
  • Desktop tests: 2145/2145 passed
  • Real macOS Seatbelt command and filesystem-worker smoke tests
  • Manual E2E coverage for:
    • workspace and /tmp writes
    • workspace-external denial
    • protected metadata
    • symlink escape
    • one-shot user approvals
    • AutoReview denial and same-turn retry suppression
    • exact approved unsandboxed execution

One existing headless test was conditionally skipped locally because the development checkout was dirty.

@YayoiNanoka

Copy link
Copy Markdown
Contributor Author

麻了,明天再解冲突吧

@YayoiNanoka

Copy link
Copy Markdown
Contributor Author

This draft PR has been superseded by a series of smaller, reviewable slices.

The sandbox implementation was split into focused PRs and merged incrementally. The remaining work is tracked by #1016.

Once #1016 is merged, this draft will no longer contain any uniquely required changes, so I’m closing it in favor of the sliced implementation.

Related to #509.

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