Governance hooks: configurable policies, threat detection, and audit trails

Resolved 💬 4 comments Opened Feb 18, 2026 by imran-siddique Closed Mar 8, 2026
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

Proposal: Governance Hooks for Codex CLI

Summary

Add configurable governance hooks that allow organizations to enforce tool policies, detect threats, and generate audit trails when Codex executes code and commands.

Motivation

Codex is a powerful terminal coding agent that executes shell commands, writes files, and modifies codebases. For enterprise adoption, organizations need:

  1. Command policies — Allowlist/blocklist shell commands, restrict file paths, limit network access
  2. Threat detection — Flag data exfiltration patterns (curl | base64, env var access, credential harvesting), privilege escalation (sudo, chmod 777), and destructive operations (rm -rf /, DROP TABLE)
  3. Audit trails — Immutable log of every command executed, file modified, and policy decision made
  4. Configurable governance levels — From permissive (log only) to strict (block + require approval)

Proposed Design

A .codex/governance.yaml file in the project root:

governance:
  level: moderate  # permissive | moderate | strict | paranoid
  
  commands:
    allowed: ["git", "npm", "python", "node", "cat", "ls", "grep"]
    blocked: ["rm -rf /", "curl * | bash", "eval"]
    require_approval: ["sudo", "docker", "kubectl"]
  
  files:
    writable_paths: ["src/", "tests/", "docs/"]
    protected_paths: [".env", "*.key", "*.pem", ".git/"]
    
  network:
    allowed_hosts: ["registry.npmjs.org", "pypi.org"]
    block_outbound: false
    
  audit:
    enabled: true
    log_path: ".codex/audit.jsonl"
    include_command_output: false  # For compliance
    
  limits:
    max_commands_per_session: 200
    max_file_modifications: 50
    max_lines_changed: 5000

Hook Points

  1. pre-command — Before executing any shell command, validate against policy
  2. pre-file-write — Before modifying any file, check path restrictions
  3. post-command — Audit the result, check for sensitive output
  4. on-violation — Block execution, log violation, optionally request human approval

Use Cases

  • Enterprise SOC: Security teams configure governance levels per-repo
  • CI/CD Safety: Codex in CI pipelines with strict policies (no network, no secrets)
  • Compliance: JSONL audit trail for SOX/SOC2 reporting
  • Developer Safety: Prevent accidental destructive commands in production repos

Context

We maintain Agent-OS governance framework and have proposed similar patterns across the agent ecosystem:

View original on GitHub ↗

4 Comments

imran-siddique · 6 months ago

For context on production validation: The governance patterns proposed here (configurable policies, threat detection, audit trails) just got merged into github/awesome-copilot (21.6K stars) — 3 PRs accepted:

The .codex/governance.yaml approach proposed here follows the same pattern. Happy to contribute an implementation.

etraut-openai contributor · 6 months ago

Thanks for the suggestion. We already support some of this in the form of execution policy rules.

We also support monitoring and telemetry and other governance features.

Please look at these mechanisms and let us know if you see any gaps for your use case.

imran-siddique · 6 months ago

Thanks @etraut-openai! Reviewed the docs you linked — Codex already has solid foundations:

  • Execution policy rules — Great for command-level allow/block. Our proposal extends this with semantic patterns (detecting data exfiltration like \curl \ | base64\, not just command names)
  • Monitoring and telemetry — Covers observability well. We're suggesting adding governance-specific audit trails (policy decisions, violation history) that feed into compliance reporting
  • Enterprise governance — The org-level controls are exactly right for the management plane

Gaps we see for our use case:

  1. Argument-level threat detection — Rules can block commands, but can they inspect arguments for patterns like credential harvesting (\cat ~/.ssh/id_rsa\), environment variable exfiltration (\^[cho \\), or encoded payloads?
  1. Composable policies — Can teams layer policies (org → repo → session) where stricter always wins? E.g., org blocks \sudo\ globally, repo adds path restrictions, session adds rate limits.
  1. Audit trail for compliance — Is there a structured, exportable audit log (JSONL) of all policy decisions (not just executions) for SOC2/SOX reporting?

If these are already covered and we're missing something in the docs, happy to close this. Otherwise, we can contribute implementations for any of these gaps.

imran-siddique · 5 months ago

Closing - project moved to microsoft/agent-governance-toolkit. Will re-submit fresh proposals from the Microsoft repo. Thank you!