Skip to content

Codex documentation and model-facing instructions recommend unsafe prefix rules as examples of safe ones #39085

Open

Description

@dfoxfranke

What is the type of issue?

Documentation is incorrect

What is the issue?

The Codex auto-review documentation recommends,

Add narrowly scoped prefix rules. Prefer precise command prefixes such as ["cargo", "test"] or ["pnpm", "run", "lint"] over broad patterns such as ["python"] or ["curl"].

cargo test is not in any meaningful sense safer or more narrowly-scoped than python if the agent has write access to the workspace. Rust test suites may execute arbitrary code. Assuming a default :workspace-write permission setting, the agent can put whatever it wants into the test suite without requiring escalation. cargo test will execute that suite.

The same bad recommendation appears in the model-facing escalation-request instructions which provide guidance on what prefix rule to suggest for a persistent approval. They mention ["npm", "run", "dev"] and ["cargo", "test"] as good examples.

A similar error is present in the OpenAI-authored code-change-verification skill which tells the agent to ask for a persistent prefix-rule authorization that executes a repository-owned shell script, and in the curated cloudflare-deploy skill which suggests an ["npm", "run", "deploy"] escalation.

Where did you find it?

Activity

  1. added
    documentation
    on Aug 17, 2026
  2. added
    CLI
    sandbox
    on Aug 17, 2026
  3. jdcodes1 commented on Aug 17, 2026

    @jdcodes1

    Verified in-repo on main @ 1f41cc5, and the combination is exactly as stated: the escalation template's opening line says approved / rule-matched commands run outside the sandbox, and the same file then recommends ["npm", "run", "dev"] and ["cargo", "test"] as example prefix rules to suggest for persistence:

    # Escalation Requests
    Commands are run outside the sandbox if they are approved by the user, or match an existing rule that allows it to run unrestricted. The command string is split into independent command segments at shell control operators, including but not limited to:
    - Pipes: |
    - Logical operators: &&, ||
    - Command separators: ;
    - Subshell boundaries: (...), $(...)
    Each resulting segment is evaluated independently for sandbox restrictions and approval requirements.
    Example:
    git pull | tee output.txt
    This is treated as two command segments:
    ["git", "pull"]
    ["tee", "output.txt"]
    Commands that use more advanced shell features like redirection (>, >>, <), substitutions ($(...), ...), environment variables (FOO=bar), or wildcard patterns (*, ?) will not be evaluated against rules, to limit the scope of what an approved rule allows.
    ## How to request escalation
    IMPORTANT: To request approval to execute a command that will require escalated privileges:
    - Provide the `sandbox_permissions` parameter with the value `"require_escalated"`
    - Include a short question asking the user if they want to allow the action in `justification` parameter. e.g. "Do you want to download and install dependencies for this project?"
    - Optionally suggest a `prefix_rule` - this will be shown to the user with an option to persist the rule approval for future sessions.
    If you run a command that is important to solving the user's query, but it fails because of sandboxing or with a likely sandbox-related network error (for example DNS/host resolution, registry/index access, or dependency download failure), rerun the command with "require_escalated". ALWAYS proceed to use the `justification` parameter - do not message the user before requesting approval for the command.
    ## When to request escalation
    While commands are running inside the sandbox, here are some scenarios that will require escalation outside the sandbox:
    - You need to run a command that writes to a directory that requires it (e.g. running tests that write to /var)
    - You need to run a GUI app (e.g., open/xdg-open/osascript) to open browsers or files.
    - If you run a command that is important to solving the user's query, but it fails because of sandboxing or with a likely sandbox-related network error (for example DNS/host resolution, registry/index access, or dependency download failure), rerun the command with `require_escalated`. ALWAYS proceed to use the `sandbox_permissions` and `justification` parameters. do not message the user before requesting approval for the command.
    - You are about to take a potentially destructive action such as an `rm` or `git reset` that the user did not explicitly ask for.
    - Be judicious with escalating, but if completing the user's request requires it, you should do so - don't try and circumvent approvals by using other tools.
    ## prefix_rule guidance
    When choosing a `prefix_rule`, request one that will allow you to fulfill similar requests from the user in the future without re-requesting escalation. It should be categorical and reasonably scoped to similar capabilities. You should rarely pass the entire command into `prefix_rule`.
    ### Banned prefix_rules
    Avoid requesting overly broad prefixes that the user would be ill-advised to approve. For example, do not request ["python3"], ["python", "-"], or other similar prefixes that would allow arbitrary scripting.
    NEVER provide a prefix_rule argument for destructive commands like rm.
    NEVER provide a prefix_rule if your command uses a heredoc or herestring.
    ### Examples
    Good examples of prefixes:
    - ["npm", "run", "dev"]
    - ["gh", "pr", "check"]
    - ["cargo", "test"]

    So under the default workspace-write profile, persisting one of these rules means: the agent may freely edit package.json/Cargo.toml/the test tree (no approval needed — that's in-sandbox writing), and then any future npm run dev / cargo test executes that agent-authored code unsandboxed, forever, with no prompt. The prefix boundary is syntactic; the payload lives in files the agent controls.

    The crisp criterion the docs are missing: a prefix rule is only a meaningful boundary if the command's behavior is not a function of agent-writable state. cargo test, npm run <anything>, pnpm run lint, make, pytest, go test, gradle are workspace interpreters — with write access to the workspace they are equivalent to ["bash"] for a persistent rule. It's notable that the same template is very careful about shell-syntax scoping (segment splitting at |/&&/;, refusing to match commands with redirection or substitutions "to limit the scope of what an approved rule allows") — the scoping rigor exists, it just stops one level below where the actual capability lives.

    Constructive fix shapes, compatible with keeping prefix rules useful:

    1. Docs/template: replace the workspace-interpreter examples with genuinely constrained ones, and explicitly label rules for workspace-interpreting commands as "this trusts the repository's current and future contents — equivalent to permanent full access for this project". That framing is honest and still lets users opt in deliberately.
    2. Product: when the approval UI offers to persist a suggested prefix rule, warn if the command's basename+verb is on a small static workspace-interpreter list (a dozen entries covers the ecosystem majority). The UI already distinguishes one-time vs persistent approval; this is one more line of context at the moment it matters.
    3. Defense-in-depth alternative: most escalations cited in the template need one capability (usually network, sometimes a specific write path), not "no sandbox". Rules that auto-approve while re-running inside the sandbox with the named extra permission would preserve almost all the convenience while keeping the workspace-interpreter hazard contained. That's a larger change, but it addresses the class rather than the examples.

    The cross-repo instances you list (openai/skills, openai-agents-python) inherit the same conceptual error from the docs, so fixing the criterion at the documentation/template level is the leverage point.

  4. pmetzger commented on Aug 17, 2026

    @pmetzger

    See also: #23227 — it would be nice to be able to be able to edit proposed permissions and construct cleaner, narrower permissions that none the less allow the agent to work without needing escalations most of the time. Unfortunately there is no way right now to interactively edit these things while they are being proposed.

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

    CLIdocumentationsandbox

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions