14 KiB
Gemini CLI: Tool Sandboxing Implementation Tasks
This document outlines the engineering plan to integrate Codex's OS-level sandboxing (macOS Seatbelt, Linux Bubblewrap/Seccomp, Windows Restricted Tokens/ACLs) into the Gemini CLI execution flow.
These tasks are structured as Epics (Parent Tasks) and Issues (Sub-tasks) suitable for importing into GitHub or Linear.
Epic 1: Foundation - Sandbox Manager & Configuration
Description: Establish the core interfaces, configuration models, and service injection points necessary to support OS-specific sandboxing without breaking the existing execution flow.
Task 1.1: Update Configuration Schema for Sandboxing
Assignee: TBD Description: We need to extend the Gemini CLI configuration to support sandbox settings.
- Action: Update
ConfigandConfigSchemainpackages/core/src/config/config.ts. - Details:
- Add a
sandboxblock. - Fields:
enabled(boolean, default false for now),allowedPaths(array of strings, e.g., workspace roots,/tmp),networkAccess(boolean or string enum).
- Add a
- Acceptance Criteria:
gemini-clican parse and validate a configuration file containing the newsandboxblock.
Task 1.2: Implement SandboxManager Base Service
Assignee: TBD Description: Create the abstract service responsible for preparing a command to run inside a sandbox.
- Action: Create
packages/core/src/services/sandboxManager.ts. - Details:
- Define the
SandboxManagerinterface with a method likeprepareCommand(req: SandboxRequest): Promise<SandboxedCommand>. - The
SandboxRequestshould include the original command, arguments,cwd, environment variables, and thesandboxconfig block. - The
SandboxedCommandshould return a possibly mutatedprogramandargsarray (e.g., returningsandbox-execas the program and the original command as args). - Implement a
StandardSandboxManagerthat handles platform-specific logic.
- Define the
- Acceptance Criteria: The interface is defined and available via the dependency injection container.
Task 1.3: Intercept Execution in ShellExecutionService
Assignee: TBD
Description:
Modify the core execution engine to route commands through the SandboxManager before spawning.
- Action: Update
packages/core/src/services/shellExecutionService.ts. - Details:
- Inject the
SandboxManagerintoShellExecutionService. - Before calling
node-pty.spawnorchild_process.spawn, pass the command payload tosandboxManager.prepareCommand(). - Use the returned
programandargsto perform the actual spawn.
- Inject the
- Acceptance Criteria: When sandboxing is disabled, tool execution behaves exactly as it did before.
Epic 2: macOS Seatbelt Integration
Description: Implement the Tier 1 Tool Sandboxing for macOS using /usr/bin/sandbox-exec and dynamically generated .sb profiles.
Task 2.1: Seatbelt Profile Generation
Assignee: TBD Description:
- Action: Implement
generateSeatbeltProfileinpackages/core/src/services/sandboxManager.ts. - Details:
- Take
allowedPathsand dynamically generate a Scheme/Lisp formatted Seatbelt profile. - Include essential "Life Support" rules:
mach-lookupforlogd,sysmond, andtrustd. - Broaden
file-map-executableto ensure system libraries can load. - Explicitly handle Git Worktree detection to allow access to external
.gitmetadata directories.
- Take
- Acceptance Criteria: Standard binaries like
ls,cat, andgitrun successfully without triggeringSignal 6(SIGABRT).
Task 2.2: Implement MacOsSandboxManager logic
Assignee: TBD Description: Connect the profile generator to the execution pipeline.
- Details:
- In
prepareCommand, generate the.sbstring. - Write this string to a secure, temporary file (
/tmp/gemini-sandbox-<id>/sandbox.sb). - Return
program: '/usr/bin/sandbox-exec'andargs: ['-f', '<tmp_profile_path>', ...originalCmd].
- In
- Acceptance Criteria: Commands executed on macOS with sandboxing enabled correctly invoke
sandbox-exec.
Epic 3: Linux Bubblewrap & Seccomp Integration
Description: Implement Tool Sandboxing for Linux using bwrap for namespaces and a Seccomp BPF filter for syscall restriction.
Task 3.1: Implement Bubblewrap Argument Generation
Assignee: TBD
Description:
Generate the bwrap CLI arguments to isolate the filesystem.
- Action: Update
StandardSandboxManagerto handle Linux. - Details:
- Map
allowedPathstobwrapbinds. E.g.,--ro-bind / / --bind <workspace> <workspace> --dev-bind /dev /dev --unshare-all. - Ensure
/dev/ptsis correctly mounted to allownode-ptyto function.
- Map
- Acceptance Criteria:
prepareCommandcorrectly outputsbwrapas the program with the appropriate isolation flags.
Epic 4: Windows Restricted Tokens & ACLs
Description: Implement Tool Sandboxing for Windows using Win32 API security primitives.
Task 4.1: Develop Windows Sandbox N-API Addon
Assignee: TBD Description: Node.js lacks native APIs for token manipulation. We must build an addon.
- Action: Create a Rust
napi-rsmodule or C++node-addon-apimodule. - Details:
- Implement logic to call
CreateRestrictedToken. - Expose functions to call
SetEntriesInAclWto dynamically grant "Allow" ACEs for the workspace directory.
- Implement logic to call
- Acceptance Criteria: The Node.js application can successfully invoke the addon methods to retrieve a restricted token handle.
Epic 5: Network Proxies & Egress Control
Description: Restrict network egress across all platforms, ensuring the agent cannot exfiltrate data.
Task 5.1: Implement Loopback Proxy & Rules
Assignee: TBD Description: Route allowed network traffic through a managed proxy.
- Action: Update all platform sandbox managers.
- Details:
- macOS: Add Seatbelt rules explicitly denying network except to specific ports or using
(allow network-outbound). - Linux: Ensure
bwrap --unshare-netis active if network is disabled.
- macOS: Add Seatbelt rules explicitly denying network except to specific ports or using
- Acceptance Criteria: Network access is strictly controlled by the sandbox manager based on policy.
Epic 6: Dynamic Sandbox Expansion & sandboxing.toml
Description: Implement a user-guided workflow that allows the sandbox to evolve based on real-world tool usage. Instead of a static profile, the agent will detect failures and propose atomic permission updates stored in a dedicated configuration file.
Task 6.1: Implement sandboxing.toml Schema & Parser
Assignee: TBD Description: Create a dedicated, human-readable TOML file for local sandbox overrides.
- Action: Define the schema and implement a parser.
- Details:
- Support fields like
extraAllowedPaths(array of strings),allowNetwork(boolean or domain list), andbinaryWhitelists. - The loader should look for this file in the project root or
.gemini/sandboxing.toml. - The
SandboxManagermust be updated to merge these rules into the OS-specific profile generation logic.
- Support fields like
- Acceptance Criteria: Changing a path in
sandboxing.tomlimmediately reflects in the next generated sandbox execution.
Task 6.2: Sandbox Violation Heuristics (Failure Detection)
Assignee: TBD Description: Enable the agent to distinguish between a "tool error" and a "sandbox block."
- Action: Update
ShellExecutionServiceto analyze exit signals and error codes. - Details:
- Detect specific signatures:
Signal 6(SIGABRT on macOS),Exit 128(Git repository/worktree errors), andEPERM(Permission Denied). - When a block is suspected, extract the paths or resources the command was attempting to access.
- Detect specific signatures:
- Acceptance Criteria: The execution engine provides a "Security Hint" in the internal error object when a sandbox violation is detected.
Task 6.3: Interactive Permission Expansion Workflow
Assignee: TBD Description: Implement the user-facing loop for approving new permissions.
- Action: Create a handler in the agent logic to process sandbox failures.
- Details:
- If a command fails due to a sandbox violation, the agent uses
ask_userto propose an update. - Example Prompt: "It looks like
nvimwas blocked. Would you like to permanently allow read/write access to~/.config/nvimin yoursandboxing.toml?" - On approval, the agent automatically updates the TOML file.
- If a command fails due to a sandbox violation, the agent uses
- Acceptance Criteria: A user can "fix" a sandbox failure for a new tool in 1-2 interactive turns.
Task 6.4: OS-Specific Rule Translators for Expansion
Assignee: TBD
Description:
Ensure that generic paths in sandboxing.toml are correctly translated across OS boundaries.
- Action: Update the
generateSeatbeltProfile(macOS) andbwrapargument generator (Linux). - Details:
- Handle tilde expansion (
~/) and environment variables in the TOML paths.
- Handle tilde expansion (
- Acceptance Criteria: A single
sandboxing.tomlentry works correctly across all supported operating systems.
Epic 7: Governance & Secret Protection
Description: Prevent the AI from tampering with its own security boundaries or accessing sensitive environment secrets.
Task 7.1: Implementation of "Write-Protected" Governance Files
Assignee: TBD Description: Ensure that the "Constitution" of the repository cannot be modified by the AI.
- Details: Update the
SandboxManagerto explicitly adddeny file-writerules for.gitignoreand.geminiignore. - Acceptance Criteria: A shell command like
rm .gitignoreorsed -i ... .gitignorefails with "Permission Denied" even when the tool has workspace-wide write access.
Task 7.2: Secret Visibility Lockdown (.env)
Assignee: TBD Description: Protect API keys and credentials stored in environment files.
- Details: Add strict "Deny Read/Write" rules for any file named
.envor matching.env.*. - Acceptance Criteria:
cat .envreturns "Permission Denied." The file is effectively invisible to the sandboxed tool.
Epic 8: Cross-Platform Ignore Enforcement
Description: Implement a generic, OS-agnostic system to ensure that any file pattern listed in .gitignore or .geminiignore is strictly inaccessible at the kernel level.
Task 8.1: Platform-Agnostic Ignore Resolver
Assignee: TBD Description: Create a core service to resolve ignore patterns into absolute paths.
- Action: Implement
packages/core/src/services/ignoreResolver.ts. - Details:
- Uses standard glob-matching logic.
- Consolidates rules from
.gitignoreand.geminiignore. - Outputs a standardized
ForbiddenResourcelist.
- Acceptance Criteria: The service correctly identifies
node_modules/or.envas forbidden regardless of the OS it's running on.
Task 8.2: Standardized "Deny" Interface in SandboxManager
Assignee: TBD Description: Update the base sandbox interface to handle forbidden resources.
- Action: Update the
prepareCommandsignature to acceptforbiddenPaths. - Details: Pass the list of standardized forbidden resources to the platform-specific implementation.
- Acceptance Criteria: Every OS-specific driver receives the same list of paths to block.
Task 8.3: OS-Specific "Deny" Implementations
Assignee: TBD Description: Implement the actual blocking mechanism for each OS.
- Details:
- macOS (Seatbelt): Generate
(deny file-read* file-write* (subpath "/path")). - Linux (Bubblewrap): Ensure the forbidden path is not mounted into the namespace.
- Windows (Restricted Tokens): Apply a "Deny" Access Control Entry (ACE) to the specific file/folder for the restricted SID used by the tool.
- macOS (Seatbelt): Generate
- Acceptance Criteria: A shell command
cat secret.txtreturns a "Permission Denied" error on all platforms ifsecret.txtis ignored.
Team Parallelization Strategy (3 Engineers)
To maximize velocity, implementation is divided by Platform Ownership. Each engineer is responsible for the full security stack on their respective OS, while coordinating on shared core logic.
Engineer A: macOS Platform Lead
- Primary Focus: Epic 2 (macOS Integration) & Epic 1 (Foundation).
- Tasks:
- Implement the macOS
sandbox-execdriver. - Epic 5 Lead: Design and implement the shared loopback proxy logic and the macOS network enforcement rules.
- Implement macOS "translators" for ignore rules and governance files.
- Implement the macOS
- Shared Responsibility: Leads the design of the generic
SandboxManagerinterface.
Engineer B: Linux Platform Lead
- Primary Focus: Epic 3 (Linux Integration) & Epic 8 (Ignore Enforcement).
- Tasks:
- Implement
bwrapintegration and the native Seccomp helper. - Epic 8 Lead: Build the generic "Ignore Resolver" that parses glob patterns for all platforms.
- Epic 7 Lead: Build the shared "Governance" logic to protect
.gitignoreand.envfiles. - Implement Linux "translators" for governance and network rules.
- Implement
Engineer C: Windows Platform Lead
- Primary Focus: Epic 4 (Windows Integration) & Epic 6 (Dynamic Expansion).
- Tasks:
- Develop the Rust/N-API addon and native process spawning for Windows.
- Epic 6 Lead: Build the shared interactive "Permission Expansion" loop and
sandboxing.tomlorchestration. - Implement Windows "translators" for ignore rules, network, and governance.
Milestone Map
- Week 1 (Interface Alignment): Engineer A/B/C agree on the
prepareCommandsignature and the standardizedForbiddenResourcelist. - Week 2-3 (Parallel Implementation): Each engineer implements the drivers for their specific OS. Engineer B and C also build the "Shared Core" modules (Ignore Resolver and Expansion Loop) in parallel.
- Week 4 (Cross-Platform Validation): Unified testing to ensure a single
sandboxing.tomlfile works correctly on all three systems.
hello world