Skip to content

Commit 529eb4f

Browse files
authored
move execpolicy quickstart (openai#7127)
1 parent c6f68c9 commit 529eb4f

File tree

2 files changed

+41
-31
lines changed

2 files changed

+41
-31
lines changed

README.md

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -69,38 +69,9 @@ Codex can access MCP servers. To configure them, refer to the [config docs](./do
6969

7070
Codex CLI supports a rich set of configuration options, with preferences stored in `~/.codex/config.toml`. For full configuration options, see [Configuration](./docs/config.md).
7171

72-
### Execpolicy Quickstart
72+
### Execpolicy
7373

74-
Codex can enforce your own rules-based execution policy before it runs shell commands.
75-
76-
1. Create a policy directory: `mkdir -p ~/.codex/policy`.
77-
2. Create one or more `.codexpolicy` files in that folder. Codex automatically loads every `.codexpolicy` file in there on startup.
78-
3. Write `prefix_rule` entries to describe the commands you want to allow, prompt, or block:
79-
80-
```starlark
81-
prefix_rule(
82-
pattern = ["git", ["push", "fetch"]],
83-
decision = "prompt", # allow | prompt | forbidden
84-
match = [["git", "push", "origin", "main"]], # examples that must match
85-
not_match = [["git", "status"]], # examples that must not match
86-
)
87-
```
88-
89-
- `pattern` is a list of shell tokens, evaluated from left to right; wrap tokens in a nested list to express alternatives (e.g., match both `push` and `fetch`).
90-
- `decision` sets the severity; Codex picks the strictest decision when multiple rules match (forbidden > prompt > allow).
91-
- `match` and `not_match` act as (optional) unit tests. Codex validates them when it loads your policy, so you get feedback if an example has unexpected behavior.
92-
93-
In this example rule, if Codex wants to run commands with the prefix `git push` or `git fetch`, it will first ask for user approval.
94-
95-
Use the `codex execpolicy check` subcommand to preview decisions before you save a rule (see the [`codex-execpolicy` README](./codex-rs/execpolicy/README.md) for syntax details):
96-
97-
```shell
98-
codex execpolicy check --policy ~/.codex/policy/default.codexpolicy git push origin main
99-
```
100-
101-
Pass multiple `--policy` flags to test how several files combine, and use `--pretty` for formatted JSON output. See the [`codex-rs/execpolicy` README](./codex-rs/execpolicy/README.md) for a more detailed walkthrough of the available syntax.
102-
103-
## Note: `execpolicy` commands are still in preview. The API may have breaking changes in the future.
74+
See the [Execpolicy quickstart](./docs/execpolicy.md) to set up rules that govern what commands Codex can execute.
10475

10576
### Docs & FAQ
10677

@@ -114,6 +85,7 @@ Pass multiple `--policy` flags to test how several files combine, and use `--pre
11485
- [**Configuration**](./docs/config.md)
11586
- [Example config](./docs/example-config.md)
11687
- [**Sandbox & approvals**](./docs/sandbox.md)
88+
- [**Execpolicy quickstart**](./docs/execpolicy.md)
11789
- [**Authentication**](./docs/authentication.md)
11890
- [Auth methods](./docs/authentication.md#forcing-a-specific-auth-method-advanced)
11991
- [Login on a "Headless" machine](./docs/authentication.md#connecting-on-a-headless-machine)

docs/execpolicy.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Execpolicy quickstart
2+
3+
Codex can enforce your own rules-based execution policy before it runs shell commands. Policies live in Starlark `.codexpolicy` files under `~/.codex/policy`.
4+
5+
## Create a policy
6+
7+
1. Create a policy directory: `mkdir -p ~/.codex/policy`.
8+
2. Add one or more `.codexpolicy` files in that folder. Codex automatically loads every `.codexpolicy` file in there on startup.
9+
3. Write `prefix_rule` entries to describe the commands you want to allow, prompt, or block:
10+
11+
```starlark
12+
prefix_rule(
13+
pattern = ["git", ["push", "fetch"]],
14+
decision = "prompt", # allow | prompt | forbidden
15+
match = [["git", "push", "origin", "main"]], # examples that must match
16+
not_match = [["git", "status"]], # examples that must not match
17+
)
18+
```
19+
20+
- `pattern` is a list of shell tokens, evaluated from left to right; wrap tokens in a nested list to express alternatives (for example, match both `push` and `fetch`).
21+
- `decision` sets the severity; Codex picks the strictest decision when multiple rules match (forbidden > prompt > allow).
22+
- `match` and `not_match` act as optional unit tests. Codex validates them when it loads your policy, so you get feedback if an example has unexpected behavior.
23+
24+
In this example rule, if Codex wants to run commands with the prefix `git push` or `git fetch`, it will first ask for user approval.
25+
26+
## Preview decisions
27+
28+
Use the `codex execpolicy check` subcommand to preview decisions before you save a rule (see the [`codex-execpolicy` README](../codex-rs/execpolicy/README.md) for syntax details):
29+
30+
```shell
31+
codex execpolicy check --policy ~/.codex/policy/default.codexpolicy git push origin main
32+
```
33+
34+
Pass multiple `--policy` flags to test how several files combine, and use `--pretty` for formatted JSON output. See the [`codex-rs/execpolicy` README](../codex-rs/execpolicy/README.md) for a more detailed walkthrough of the available syntax.
35+
36+
## Status
37+
38+
`execpolicy` commands are still in preview. The API may have breaking changes in the future.

0 commit comments

Comments
 (0)