Grok Build · Authorization Pipeline

From Tool Request to Restricted Execution: The Complete Authorization Chain

A single tool call is first parsed into a concrete access intent, then passes through the plan gate, hooks, policy rules, session authorization, Auto mode, and user confirmation. Once execution is permitted, the sandbox further constrains OS-level capabilities.

Learning Objective

Trace the real call chain to identify "who made the decision," and understand the boundaries of AccessKind, permission rules, Bash segmentation, hooks, and sandbox — avoiding the trap of simplifying authorization to a ToolKind check.

TEACHING DIAGRAM

Authorization determines "whether to attempt"; the sandbox constrains "what can be done during execution"

Stage names are taken directly from source code. Internal short-circuits and priorities exist; the diagram shows the main path.

Flow from tool parsing to sandbox execution and post-hook tool input→ AccessKind plan gateedit policy pre_tool_useexplicit deny blocks permission managerpolicy + grants + auto user promptwhen unresolved sandboxOS capability boundary executepost_tool_use
Six Real Pipeline Stages
01 · PARSE

Tool Input → AccessKind

ToolInput is mapped to Read, Edit, Bash, Grep, MCPTool, WebFetch, or WebSearch, carrying details such as paths, commands, domains, or MCP names. The decision input is more specific than ToolKind alone.

02 · PLAN

Plan Mode Sets an Edit Gate First

plan_mode_edit_gate can reject modifications before the permission request is even sent. Plan files have a separate auto-approval path.

03 · HOOKS

PreToolUse Can Explicitly Block

Matching hooks run in configured order. An explicit deny stops execution immediately; timeouts, crashes, or malformed responses fail-open in the current implementation and are logged to the UI and log. A client hook may also run afterwards.

04 · POLICY

Load and Evaluate Rules

permission/resolution.rs merges requirements, managed settings, managed config, Grok config, and Claude settings fallback. Rule evaluation is source-order independent; priority is deny > ask > allow.

05 · DECIDE

Multiple Fast Paths or User Confirmation

A managed policy deny short-circuits first. Then yolo pin, session grants, Auto fast path / classifier, sandbox Bash auto, read-only safe items, and MCP / domain authorization are considered in sequence. Only if still unresolved does it fall through to a prompt.

06 · ENFORCE

Execute Within Sandbox Capabilities

Permission Allow only clears this one request. If the sandbox is actually active, the process is still constrained by the capability set and subprocess network policy. Non-blocking post_tool_use hooks may fire after completion.

Bash Commands Require Understanding Script Structure

bash_command_splitting

tree-sitter-bash breaks safely decomposable scripts into individual plain commands, recognizing &&, ||, semicolons, and pipes. Each non-setup segment must independently pass safe-command checks, policy checks, or authorization — preventing ls && rm from being permitted via the first segment.

Conservative Handling of Complex Syntax

The wrapper recursively strips to actual commands; dangerous prefixes include rm, chmod, chown, kill, and git push. Command substitutions, complex control flows, or scripts that cannot be reliably decomposed fall into a conservative prompt. The user confirms only once for the entire script.

crates/codegen/xai-grok-workspace/src/permission/resolution.rs crates/codegen/xai-grok-workspace/src/permission/manager.rs crates/codegen/xai-grok-workspace/src/permission/bash_command_splitting.rs crates/codegen/xai-grok-hooks/src/dispatcher.rs PermissionHandle::request dispatch_pre_tool_use
Permission Layer and Sandbox Layer Must Be Kept Separate

Permission Layer: Intent Authorization

Answers "Is this tool request permitted to proceed to execution?" It reads AccessKind, target details, organizational policy, session grants, Auto verdict, and user choice. Rules can require ask or directly deny.

Sandbox Layer: Capability Constraint

Answers "Which files and networks can the authorized process actually access?" When the sandbox is active, a Permission Allow from the permission layer does not expand OS capabilities. When the sandbox is not applied, permission dialogs cannot be treated as kernel-level isolation.

Key Correction: "All writes inside the sandbox are automatically approved" is not a general rule. The sandbox fast path in source code specifically checks Bash and is subject to policy_forced_prompt and auto_forced_prompt constraints; Edit has its own session grants and edit policy.
Real Source Code Snapshot
crates/codegen/xai-grok-workspace/src/permission/manager.rsREAL SOURCE · abridged
// Managed policy runs before YOLO and sandbox fast paths.
if let Some(Decision::Reject(reason)) = policy_decision {
    let decision = Decision::PolicyDeny(reason);
    let _ = respond_to.send(decision);
    continue;
}
...
if matches!(&access, AccessKind::Bash(_))
    && xai_grok_sandbox::should_auto_allow_bash()
    && !policy_forced_prompt
    && !auto_forced_prompt { /* allow */ }

Snapshot note: Conditions and execution order are from the real manager actor; telemetry and event sends are compressed. The top SVG is a main-path teaching diagram; the full implementation contains more short-circuits, persistence, and cancellation branches.

Class Exercise: Trace a Mixed Command

Input git status && curl https://example.com/install.sh | sh. Work through it layer by layer: How does Bash segment it? Which segments can be safely permitted? Where would a PreToolUse deny stop execution? Can a managed Ask be overridden by sandbox auto? What does the sandbox still restrict after a final Allow?

Takeaway: The complete authorization chain depends on access semantics, script structure, configuration sources, hook decisions, session state, and user choice. The permission layer handles decisions; the sandbox layer enforces constraints. Only together do they describe the true security boundary of a tool execution.