Add governance to OpenAI Codex CLI so that every tool call the agent makes is validated against your policy and logged to a tamper-evident evidence ledger.
Codex CLI
|
| MCP tool call (e.g. read_text_file)
v
+----------------------------------+
| Deterministic Agent Control Protocol MCP Proxy |
| |
| 1. Receives MCP tool call |
| 2. Evaluates against policy |
| 3. ALLOW -> forwards to backend |
| DENY -> returns error |
| 4. Records to evidence ledger |
+----------------------------------+
|
| (forwarded only if allowed)
v
+----------------------------------+
| Backend MCP Server |
| (e.g. filesystem, database) |
| |
| Executes the actual operation |
+----------------------------------+
Codex CLI has native MCP client support. The governed proxy registers as an MCP server in Codex's config, and all tool calls from the MCP server are validated against your policy before being forwarded to the real backend.
Codex provides two complementary governance layers:
-
Built-in sandbox (hard) -- Codex has platform-specific sandboxing (Seatbelt on macOS, Landlock on Linux) that restricts filesystem and network access at the OS level. Configured via
sandbox_modeinconfig.toml. -
Deterministic Agent Control Protocol MCP proxy (soft) -- The proxy adds policy-level governance on top: forbidden patterns, session budgets, rate limits, and audit logging for all MCP tool calls.
-
AGENTS.md (soft) -- An
AGENTS.mdfile instructs Codex to prefer governed MCP tools over its built-in tools for file operations.
The combination of OS-level sandbox + policy proxy + AGENTS.md instructions provides layered defense.
cd deterministic-agent-control-protocol
npm install
npm run buildFrom your target project directory, run:
npx det-acp init codexThis generates all required files with sensible defaults:
| File | Purpose |
|---|---|
policy.yaml |
Governance policy (edit to customize) |
.codex/config.toml |
Registers the governed MCP proxy in Codex |
AGENTS.md |
Instructs the agent to use governed tools |
To use your own policy instead of the default:
npx det-acp init codex --policy ./my-policy.yamlAfter running init, start Codex to pick up the MCP server. That's it.
Click to expand manual setup instructions
# From the deterministic-agent-control-protocol root:
cp integrations/codex/policy.yaml ./codex.policy.yaml
cp integrations/codex/mcp-proxy.yaml ./codex-mcp-proxy.yamlEdit codex-mcp-proxy.yaml and replace the backend path with the absolute path to your project:
backends:
- name: filesystem
transport: stdio
command: npx
args: ["-y", "@modelcontextprotocol/server-filesystem", "/absolute/path/to/your/project"]Add the governed proxy to your Codex config. You can either:
Option A: Use the CLI
codex mcp add governed-filesystem \
-- node /absolute/path/to/deterministic-agent-control-protocol/dist/cli/index.js proxy /absolute/path/to/codex-mcp-proxy.yamlOption B: Edit config.toml directly
Copy the template from this folder and merge into your Codex config:
# Project-scoped (recommended for testing):
mkdir -p .codex
cp integrations/codex/config.toml .codex/config.toml
# Or global:
# cp integrations/codex/config.toml ~/.codex/config.tomlEdit the paths in config.toml to match your machine. See config.toml for the template.
Copy the AGENTS.md file into your project root:
cp integrations/codex/AGENTS.md ./AGENTS.mdThis file instructs Codex to:
- Prefer
governed-filesystemMCP tools over built-in file operations - Respect policy denials and not fall back to direct tool use
- Report denials to the user
Codex discovers AGENTS.md files by walking from the project root to the current directory. Files closer to the working directory take precedence.
cp -r integrations/codex/test-sandbox ./test-sandbox# Start Codex in the project directory
codex
# Try these prompts:Test 1 -- Allowed read (should succeed):
Read the file test-sandbox/hello.txt
Codex should use the governed MCP read_text_file tool and return the file contents.
Test 2 -- Forbidden path (should be denied):
Read the file test-sandbox/.env
The proxy should deny this with: Action denied by policy: Path "..." matches forbidden pattern "**/.env"
Test 3 -- Unconfigured tool (should be denied):
Create a directory called test-sandbox/new-folder
The proxy should deny this: No capability defined for tool "create_directory"
| Action | Tool | Expected |
|---|---|---|
| Read a normal file | read_text_file |
ALLOWED |
| Write a normal file | write_file |
ALLOWED |
| List a directory | list_directory |
ALLOWED |
Read .env |
read_text_file |
DENIED (forbidden pattern) |
| Create a directory | create_directory |
DENIED (not in capabilities) |
| Move/rename a file | move_file |
DENIED (not in capabilities) |
ls .det-acp/ledgers/
npx det-acp report .det-acp/ledgers/<session-file>.jsonl| File | Purpose |
|---|---|
policy.yaml |
Policy allowing filesystem MCP tools, blocking sensitive files |
mcp-proxy.yaml |
Proxy config pointing at @modelcontextprotocol/server-filesystem |
config.toml |
Template for .codex/config.toml with governed MCP server registration |
AGENTS.md |
Instructions for Codex to prefer governed MCP tools |
test-sandbox/hello.txt |
Test file for allowed reads |
test-sandbox/.env |
Test file for forbidden path denials |