Skip to content

Expose trusted resolved execution context to policy hooks #54427

Open

Description

@erickb336

Trusted resolved execution context for policy hooks

Tracking use case: erickb336/sage-stack#243. This request concerns a supported runtime contract for policy extensions. It is separate from required-hook failure handling in #41979.

Related reports: #32360 and #50271 cover effective working directory; #40996 covers permission context. This request brings those needs together with executor identity, filesystem namespace, shell resolution, and per-call freshness. If an existing supported interface covers them, please point us to it.

Problem

A policy hook needs the settings that the executor will actually use. Original model arguments do not establish those settings. A hook cannot safely infer execution paths from its own environment when a command selects a different working directory, shell, or remote executor.

In rust-v0.162.1, the exec_command PreToolUse payload contains the command string. The hook cwd uses the local environment cwd, with the turn cwd as fallback. These fields do not attest the pending command's resolved execution context.

Sources checked:

Requested capability

Provide a supported, versioned policy interface for the resolved operation before execution. An extension to an existing hook or a separate runtime callback could satisfy this request. The interface must bind evidence to the authenticated session, actor, turn, and exact tool call.

Required evidence or equivalent trusted checks:

  • Selected executor and filesystem namespace, including whether execution is local or remote.
  • Effective working directory after resolving omitted, empty, relative, and explicit inputs.
  • Effective shell executable, shell type, and invocation/login behavior.
  • The lookup settings needed for executable and path policy, including PATH, HOME, and CDPATH, without exposing credentials or a full environment dump.
  • Effective sandbox and permission policy, including permitted additions and inherited settings.
  • A supported way to evaluate relevant filesystem, symlink, executable identity, and checkout evidence in that same namespace.

Specify when evidence is captured, how rewrites affect it, and what invalidates an earlier decision. A changed executor, directory, permission setting, or operation must require a fresh decision. Evidence for one call must not authorize another. Successful extension policy must preserve native sandbox and approval checks.

The interface must state its limits. Shell startup scripts and arbitrary programs can change behavior after this point. Context metadata is not proof that a command is harmless and does not replace a filesystem sandbox.

Validation examples

  1. Compare omitted and explicit workdir inputs with the command's actual directory in an isolated fixture.
  2. Compare requested shell strings with the runtime-selected executable and invocation.
  3. Exercise inherited and explicit permission settings without bypassing native approvals.
  4. Verify local and remote namespaces; local filesystem inspection must not stand in for remote evidence.
  5. Refuse mismatched session, actor, turn, or call identities, stale snapshots, and changed operations.
  6. Verify denial prevents the operation. Separately cover hook timeout, exception, and transport failure through the fail-closed contract.

Current Sage boundary

Sage can recover original requested arguments from protected native transcripts. Its verified fixture path does not establish a complete installed evaluator. Automatic activation remains disabled. Native probes with simulated model responses establish only the behavior they directly observe.

Evidence limits

The source audit covers rust-v0.162.1. At submission, rust-v0.163.0 is the latest published release; it has not been source-audited or native-tested in this investigation. The cited 0.162.1 source was read directly. This request does not claim a new native comparison run or that every possible runtime interface was exhaustively excluded.

Sage needs a supported producer or a separately designed execution boundary. Model-supplied fields cannot supply runtime authority.

Activity

  1. added
    enhancement
    hooks
    sandbox
    on Oct 15, 2026
  2. AndrewDongminYoo commented on Oct 31, 2026

    @AndrewDongminYoo

    Additional use case: resolved native subagent settings before spawn

    The same resolved-context requirement applies to admitting a native spawn_agent call before a child begins work.

    Observed scope

    • macOS ChatGPT app using its bundled codex app-server, reporting codex-cli 0.166.0-alpha.5.1.
    • Source inspected at tag rust-v0.166.0-alpha.5.1, peeled commit f79b26ccbb3116b052544666a181012fb45dc49b.
    • A user-defined hook checks registered roles, explicit model/reasoning effort, and configuration provenance before allowing delegation. It currently declines app-server spawns when the final child settings cannot be established. That denial is emitted by the local policy consumer.

    Why requested arguments are insufficient

    Child configuration preparation applies requested model/reasoning overrides, then applies the selected role.
    Role application resolves that role from the live parent configuration and loads its role file.
    Consequently, pinning a tool argument such as reasoning_effort: "high" does not establish the final child setting when the role layer subsequently pins a different value.

    The PreToolUse request and serialized command input expose the calling context and requested tool input, without the prepared child's effective model/effort or role-source provenance.
    The generic hook dispatch also permits input rewrites before the handler executes.
    Reading the on-disk configuration or inspecting the parent's persisted model/effort cannot establish an unexposed live role override.

    Requested extension of this issue

    Expose a trusted, versioned pre-spawn settings snapshot outside caller-controlled tool_input, through the existing hook or an equivalent supported admission callback:

    • Effective child model and reasoning effort after role resolution, plus selected role and enough source identity/provenance to validate that selection.
    • Binding to the actual session, turn, tool call and exact normalized spawn arguments.
    • Recalculation and a fresh policy decision when a hook rewrites arguments that affect resolution.
    • Reuse of the approved prepared configuration for actual child creation, so a later role-file read cannot silently change what was approved.

    A model-authored snapshot inside tool arguments would not provide this evidence.
    The payload need not expose prompts, credentials, a full configuration dump or the ambient environment.
    Existing native sandbox and approval checks should remain in force.

    Acceptance checks and evidence limits

    An app-server integration fixture should compare the approved snapshot with the actual persisted child model/effort, exercise a role that overrides the requested effort, and verify zero child creation after a policy denial.
    Changed arguments, stale or mismatched identities, and role-file changes between validation and dispatch should not reuse the earlier approval.

    This contribution is grounded in the pinned source and the local consumer's denial; no patched producer or end-to-end snapshot implementation was completed.
    It does not demonstrate that an incorrect model ran, a native policy was bypassed, or the desktop frontend crashed.
    The missing producer-side contract is the remaining integration requirement.

    #33314 concerns full-profile application and observable spawn metadata; #44095 concerns spawn/lifecycle correlation.
    The specific addition here is making resolved child settings available before admission, with rewrite and dispatch consistency, within this existing trusted-context request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhookssandbox

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions