Skip to content

Rules are useless #9206

Closed
Closed

Description

@yassenb

What version of Codex is running?

0.80.0

What subscription do you have?

Plus

Which model were you using?

gpt-5.2-codex

What platform is your computer?

Linux 6.8.0-90-generic x86_64 x86_64

What issue are you seeing?

Codex prompts me for every test in needs to run, for example rspec some_spec.rb

What steps can reproduce the bug?

Add a rule file in ~/.codex/rules/ with something like:

# rspec via PATH or binstubs
prefix_rule(
    pattern = [["rspec", "bin/rspec", "./bin/rspec"]],
    decision = "allow",
    justification = "Allow rspec outside the sandbox.",
)

# bundle exec rspec
prefix_rule(
    pattern = ["bundle", "exec", "rspec"],
    decision = "allow",
    justification = "Allow bundle exec rspec outside the sandbox.",
)

Then tell codex to run some test

What is the expected behavior?

Codex runs the test without having to require permissions

Additional information

The problem is that every command is actually prefixed with your shell, for example all the rules that I have that were created automatically go like:

prefix_rule(pattern=["/usr/bin/zsh", "-lc", "APP_ENV=test bundle exec rspec spec/web/gql/operator/query_spec.rb spec/web/gql/operator/mutations/delete_spec.rb"], decision="allow")

So every command is prefixed by my shell /usr/bin/zsh which makes rules useless unless they're an absolute exact match. So there's no way for me to say "run any tests with rspec without requiring permission" while still keeping Codex safe and not allowing everything

Activity

  1. added
    bug
    on Jan 14, 2026
  2. added
    CLI
    sandbox
    on Jan 14, 2026
  3. github-actions commented on Jan 14, 2026

    @github-actions
    Contributor
  4. bolinfest commented on Jan 14, 2026

    @bolinfest
    Collaborator

    @yassenb In general, we have logic that parses invocations like bash -lc COMMAND into its constituent parts and runs them through the rules individually:

    if let Some(all_commands) = parse_shell_lc_plain_commands(&command)
    && !all_commands.is_empty()
    && all_commands
    .iter()
    .all(|cmd| is_safe_to_call_with_exec(cmd))
    {
    return true;
    }
    false

    Though we don't match the case when COMMAND starts with an env var today.

    As a workaround, what if you create a wrapper script, bundle.sh, that does:

    #!/bin/zsh
    
    APP_ENV=test bundle "$@"
    

    and create a prefix_rule() for bundle.sh?

  5. yassenb commented on Jan 15, 2026

    @yassenb
    Author

    Yes, sorry for the confusion, it's indeed the environment variable in the prefix that's causing this not to work for me. Feel free to close this or update the details to point out it's not working only for this case. Thank you.

  6. jon-sully commented on Feb 6, 2026

    @jon-sully

    For those who ended up here and are having a hard time, key note, you need to restart Codex (the app, the CLI process, or VS Code if you run the extension) before the rule changes take effect. Nonetheless I recommend a bin-stub style wrapper like suggested above... for my Rails app it looks like:

    #!/usr/bin/env bash
    
    PATH="$HOME/.asdf/shims:$PATH" BUNDLE_USER_HOME="$PWD/tmp/bundle" ./bin/rspec "$@"

    But YMMV. Just remember to restart codex after making rule changes!

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

    CLIbugsandbox

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions