Skip to content

Allow user to create rules with improved Starlark support #15214

Open

Description

@hktonylee

What variant of Codex are you using?

CLI

What feature would you like to see?

Currently the rules only support prefix_rule which is very limiting because it only matches the whole literal. There were multiple issues before and the solution would be to improve the rules engine (say, #11298, #8537, #13175 and probably more)

Personally, I am using codex to handle some ops command calls. And in lot of cases (>80% of the time), the commands are just differed from each other a little bit. Let's say, cat xxx | head -5 and cat xxx | head -6. However, due to how the prefix_rule is implemented, codex will ask for approval for each of these variants.

Image

( I need to approve for different file and message each time :-( )

For projects that requires mixed use of kubectl and bash, it is very typical for user to review and approve 5-10 very similar commands for each message that the user sends. The non-stop approval steps are actually not safe (or dangerous) because people will get tired and approve something that should not be approved.

Since the rules are using Starlark syntax. I would propose to create another kind of rule, called general_rule(), which accepts a custom Starlark function to approve / reject. For example,

def my_rules(args):
  return args[0] == "super-cli"

def is_inline_shell_script(func):
  def _inner(args):
    return args[0] in ("bash", "zsh") and args[1] == "-c" and func(args[2:])
  return _inner

general_rule(predicate=my_rules, decision="allow")
general_rule(predicate=is_inline_shell_script(my_rules), decision="allow")

This can allow user to leverage the community (or AI) to build better rule handling system. Let's say, people can implement rules to handle && and || shell conditions - by implementing a shell script parser and intersection of nested rules.

Additional information

No response

Activity

  1. added
    enhancement
    on Mar 19, 2026
  2. added
    CLI
    sandbox
    on Mar 19, 2026
  3. removed
    CLI
    on Mar 19, 2026
  4. github-actions commented on Mar 19, 2026

    @github-actions
    Contributor

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

    Powered by Codex Action

  5. ehendrix23 commented on Apr 8, 2026

    @ehendrix23

    Just in further support, I regulary have it wanting to run items like:

    "/bin/zsh -lc \"QT_QPA_PLATFORM=offscreen uv run pytest -q tests/unit/codex.py\"" 
    

    But the only way for me currently to auto-approve running of uv run pytest like that is a rule allowing "/bin/zsh -lc".

  6. alexander-zuev commented on Jul 10, 2026

    @alexander-zuev

    Please support positional wildcards in rules. Monorepos need to allow pnpm --filter <any-package> test|build|lint without also allowing deploy or migration scripts, e.g. ["pnpm", "--filter", ANY, one_of("test", "build", "lint")].

  7. benglewis commented on Oct 11, 2026

    @benglewis

    I had Codex implement a version of this in my fork branch. It adds general_rule(predicate=...) with retained Starlark functions, boolean results, best-effort evaluation limits, and rejection on predicate errors. It also preserves restrictive rule precedence and checks shell wrappers without letting an outer allow approve unrelated inner commands.

    The combined implementation passed 43 execpolicy tests and 101 focused core tests locally. Given the policy on external PRs, I'm sharing it as a reference in case the upstream team would consider implementing something similar.

  8. hktonylee commented on Oct 16, 2026

    @hktonylee
    Author

    This issue may become obsoleted now because the new auto approval system can automate custom rules in most cases.

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

    enhancementsandbox

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions