Rules are useless

Resolved 💬 4 comments Opened Jan 14, 2026 by yassenb Closed Jan 15, 2026
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

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

View original on GitHub ↗

4 Comments

github-actions[bot] contributor · 7 months ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #8537
  • #8394

Powered by Codex Action

bolinfest collaborator · 7 months ago

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

https://github.com/openai/codex/blob/e1447c30093568d44f2b5422d4b7fbba80bff230/codex-rs/core/src/command_safety/is_safe_command.rs#L30-L38

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?

yassenb · 7 months ago

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.

jon-sully · 6 months ago

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!