Part 6 · Inside a Production Coding Agent

From Tool Request to Restricted Execution

Tracing the full authorization chain through ToolKind, permission decisions, and platform sandboxing

THE QUESTION THIS PAGE ANSWERS

ANSWER FIRST

What is the key idea behind “From Tool Request to Restricted Execution”?

Tracing the full authorization chain through ToolKind, permission decisions, and platform sandboxing

DECISION RULE

Make the claim earn its place. Use this page as a decision aid, not a definition to memorize. Connect the idea to one real task, one observable result, and one failure that would change your mind.

TRY NEXT

Write one question you could answer with evidence after trying this idea.

WATCH FOR

A conclusion that sounds complete but leaves the key assumption untested.

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.

Why “Authorization determines "whether to attempt"; the sandbox constrains "what can be done during execution"” depends on the operation

“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…” makes the structure concrete. The useful comparison is not which name sounds more advanced, but how the data is arranged and how far the most common operation has to travel.

Read a structure through access and change

“Stage names are taken directly from source code.” exposes a trade-off that is easy to miss: reading by position, looking up by key, adding at either end, inserting in the middle, and traversing relationships do not favor the same organization. A structure that is fast for one operation is not automatically fast for all of them.

Count scale and update frequency together

Use “Input git status && curl https://example.com/install.sh | sh .” as a boundary check. Write down the data size, the dominant operation, and the latency you can accept before deciding whether an AI-generated structure actually fits.

From “Authorization determines "whether to attempt"; the sandbox constrains "what can be done during execution"” to “Tool Input → AccessKind”

“Authorization determines "whether to attempt"; the sandbox constrains "what can be done during execution"” grounds the problem in “Stage names are taken directly from source code. Internal short-circuits and priorities exist; the diagram shows the main path”. “Tool Input → AccessKind” then moves it toward “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”. Together, they show that the lesson is not just a conclusion to remember, but a claim with conditions.

Carry the judgment into the next situation

When you meet a new data structure, do not begin by memorizing its definition. Write down the most frequent operation, estimate scale and update behavior, and check whether the structure satisfies all three conditions.

  • “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
  • “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
  • “The closing point”: 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…

The final “The closing point” brings the discussion to “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…”. The useful thing to carry forward is knowing which judgments must be revisited when input, scale, or risk changes.

Mark as learned Your reading progress updates automatically
← PreviousNext →

Keep reading

The next useful article in the thread.

ARTICLE DISCUSSION

Leave one useful thought here.

Keep the idea that clicked, the question that stayed open, or a small note for the next learner.

Discussing From Tool Request to Restricted Execution Inside a Production Coding Agent
3discussionsArticle discussion · synced with the Circle
View in the learning circle
AM
Asha MorganContent editor
INSIGHTField note

I turned one judgment from this article into a small experiment I could run today. Knowing what to observe next is more useful than simply remembering the conclusion.

ARTICLE DISCUSSION7 helpful
LH
Lin HarperIndie developer
INSIGHTInsight

After reading this, I first looked for the conditions behind the idea instead of copying the method into a project. That order made the later trade-offs much clearer.

ARTICLE DISCUSSION5 helpful
KM
Kiki MooreProduct operations
QUESTIONQuestion

When this judgment reaches real work, which constraint should be added first? I am curious which step matters most between reading and the first practical attempt.

ARTICLE DISCUSSION4 helpful