Commit Graph

1438 Commits

Author SHA1 Message Date
Michael Bolin
052d76fcfd merge commit for archive created by Sapling 2025-05-22 14:48:21 -07:00
Michael Bolin
f7004111ae fix: overhaul how we spawn commands under seccomp/landlock on Linux 2025-05-22 14:48:15 -07:00
Michael Bolin
ae0466b302 Merge 05679ff99a into sapling-pr-archive-bolinfest 2025-05-22 14:47:31 -07:00
Michael Bolin
05679ff99a fix: overhaul how we spawn commands under seccomp/landlock on Linux 2025-05-22 14:47:02 -07:00
Michael Bolin
852513bb14 Merge a93042411d into sapling-pr-archive-bolinfest 2025-05-22 13:37:58 -07:00
Michael Bolin
a93042411d fix: for the @native release of the Node module, use the Rust version by default 2025-05-22 13:37:53 -07:00
Michael Bolin
89766a9629 Merge ba4f2695c0 into sapling-pr-archive-bolinfest 2025-05-22 13:33:57 -07:00
Michael Bolin
ba4f2695c0 fix: for the @native release of the Node module, use the Rust version by default 2025-05-22 13:33:51 -07:00
Michael Bolin
cb379d7797 feat: introduce support for shell_environment_policy in config.toml (#1061)
To date, when handling `shell` and `local_shell` tool calls, we were
spawning new processes using the environment inherited from the Codex
process itself. This means that the sensitive `OPENAI_API_KEY` that
Codex needs to talk to OpenAI models was made available to everything
run by `shell` and `local_shell`. While there are cases where that might
be useful, it does not seem like a good default.

This PR introduces a complex `shell_environment_policy` config option to
control the `env` used with these tool calls. It is inevitably a bit
complex so that it is possible to override individual components of the
policy so without having to restate the entire thing.

Details are in the updated `README.md` in this PR, but here is the
relevant bit that explains the individual fields of
`shell_environment_policy`:

| Field | Type | Default | Description |
| ------------------------- | -------------------------- | ------- |
-----------------------------------------------------------------------------------------------------------------------------------------------
|
| `inherit` | string | `core` | Starting template for the
environment:<br>`core` (`HOME`, `PATH`, `USER`, …), `all` (clone full
parent env), or `none` (start empty). |
| `ignore_default_excludes` | boolean | `false` | When `false`, Codex
removes any var whose **name** contains `KEY`, `SECRET`, or `TOKEN`
(case-insensitive) before other rules run. |
| `exclude` | array&lt;string&gt; | `[]` | Case-insensitive glob
patterns to drop after the default filter.<br>Examples: `"AWS_*"`,
`"AZURE_*"`. |
| `set` | table&lt;string,string&gt; | `{}` | Explicit key/value
overrides or additions – always win over inherited values. |
| `include_only` | array&lt;string&gt; | `[]` | If non-empty, a
whitelist of patterns; only variables that match _one_ pattern survive
the final step. (Generally used with `inherit = "all"`.) |


In particular, note that the default is `inherit = "core"`, so:

* if you have extra env variables that you want to inherit from the
parent process, use `inherit = "all"` and then specify `include_only`
* if you have extra env variables where you want to hardcode the values,
the default `inherit = "core"` will work fine, but then you need to
specify `set`

This configuration is not battle-tested, so we will probably still have
to play with it a bit. `core/src/exec_env.rs` has the critical business
logic as well as unit tests.

Though if nothing else, previous to this change:

```
$ cargo run --bin codex -- debug seatbelt -- printenv OPENAI_API_KEY
# ...prints OPENAI_API_KEY...
```

But after this change it does not print anything (as desired).

One final thing to call out about this PR is that the
`configure_command!` macro we use in `core/src/exec.rs` has to do some
complex logic with respect to how it builds up the `env` for the process
being spawned under Landlock/seccomp. Specifically, doing
`cmd.env_clear()` followed by `cmd.envs(&$env_map)` (which is arguably
the most intuitive way to do it) caused the Landlock unit tests to fail
because the processes spawned by the unit tests started failing in
unexpected ways! If we forgo `env_clear()` in favor of updating env vars
one at a time, the tests still pass. The comment in the code talks about
this a bit, and while I would like to investigate this more, I need to
move on for the moment, but I do plan to come back to it to fully
understand what is going on. For example, this suggests that we might
not be able to spawn a C program that calls `env_clear()`, which would
be...weird. We may still have to fiddle with our Landlock config if that
is the case.
codex-rs-6a77484c94956d5cd319da3f8500b178ec93fc90-1-rust-v0.0.2505220956
2025-05-22 09:51:19 -07:00
Michael Bolin
f3f0a52e11 merge commit for archive created by Sapling 2025-05-22 09:41:49 -07:00
Michael Bolin
cdba9bff41 feat: introduce support for shell_environment_policy in config.toml 2025-05-22 09:41:38 -07:00
Michael Bolin
1cd9cd2757 merge commit for archive created by Sapling 2025-05-22 09:25:36 -07:00
Michael Bolin
25614adc3c feat: introduce support for shell_environment_policy in config.toml 2025-05-22 09:25:30 -07:00
Michael Bolin
b651d0d0a2 Merge e9cb029000 into sapling-pr-archive-bolinfest 2025-05-21 23:04:22 -07:00
Michael Bolin
e9cb029000 feat: introduce support for shell_environment_policy in config.toml 2025-05-21 23:03:52 -07:00
Michael Bolin
ef7208359f feat: show Config overview at start of exec (#1073)
Now the `exec` output starts with something like:

```
--------
workdir:  /Users/mbolin/code/codex/codex-rs
model:  o3
provider:  openai
approval:  Never
sandbox:  SandboxPolicy { permissions: [DiskFullReadAccess, DiskWritePlatformUserTempFolder, DiskWritePlatformGlobalTempFolder, DiskWriteCwd, DiskWriteFolder { folder: "/Users/mbolin/.pyenv/shims" }] }
--------
```

which makes it easier to reason about when looking at logs.
codex-rs-79cb07bf70a9036200aa2b61b211fe47ea13184a-1-rust-v0.0.2505212314
2025-05-21 22:53:02 -07:00
Michael Bolin
3e01e37362 merge commit for archive created by Sapling 2025-05-21 22:45:54 -07:00
Michael Bolin
7cdd8176ed feat: introduce support for shell_environment_policy in config.toml 2025-05-21 22:45:49 -07:00
Michael Bolin
2b5b341446 Merge 52bcd59147 into sapling-pr-archive-bolinfest 2025-05-21 22:42:32 -07:00
Michael Bolin
52bcd59147 feat: introduce support for shell_environment_policy in config.toml 2025-05-21 22:42:28 -07:00
Michael Bolin
516040b382 Merge 7a06b5d318 into sapling-pr-archive-bolinfest 2025-05-21 22:38:07 -07:00
Michael Bolin
7a06b5d318 feat: show Config overview at start of exec 2025-05-21 22:37:59 -07:00
Michael Bolin
b7d987118f merge commit for archive created by Sapling 2025-05-21 22:30:49 -07:00
Michael Bolin
c6069765bc feat: introduce support for shell_environment_policy in config.toml 2025-05-21 22:30:43 -07:00
Michael Bolin
e51c1717d9 merge commit for archive created by Sapling 2025-05-21 22:23:55 -07:00
Michael Bolin
44a22df89e feat: introduce support for shell_environment_policy in config.toml 2025-05-21 22:23:48 -07:00
Michael Bolin
de3c0b8f75 Merge 6c6fbc85c3 into sapling-pr-archive-bolinfest 2025-05-21 22:05:47 -07:00
Michael Bolin
6c6fbc85c3 feat: introduce support for shell_environment_policy in config.toml 2025-05-21 22:05:42 -07:00
Michael Bolin
4852bbf178 merge commit for archive created by Sapling 2025-05-21 21:57:01 -07:00
Michael Bolin
ddb8a60eb8 feat: introduce support for shell_environment_policy in config.toml 2025-05-21 21:56:57 -07:00
Michael Bolin
6a32b6f322 Merge f61a0e483f into sapling-pr-archive-bolinfest 2025-05-21 21:55:32 -07:00
Michael Bolin
f61a0e483f feat: introduce support for shell_environment_policy in config.toml 2025-05-21 21:55:28 -07:00
Michael Bolin
0ebc41f4d8 merge commit for archive created by Sapling 2025-05-21 21:48:48 -07:00
Michael Bolin
ace9888b84 feat: introduce support for shell_environment_policy in config.toml 2025-05-21 21:48:42 -07:00
Michael Bolin
151d66910e merge commit for archive created by Sapling 2025-05-21 21:26:14 -07:00
Michael Bolin
dd4ce3c9ce feat: introduce support for shell_environment_policy in config.toml 2025-05-21 21:26:03 -07:00
Michael Bolin
dec39f4dc0 merge commit for archive created by Sapling 2025-05-21 21:13:12 -07:00
Michael Bolin
7230d8aeeb feat: introduce support for shell_environment_policy in config.toml 2025-05-21 21:13:07 -07:00
Michael Bolin
0908b84a45 merge commit for archive created by Sapling 2025-05-20 16:35:58 -07:00
Michael Bolin
4bc7159c64 feat: introduce support for shell_environment_policy in config.toml 2025-05-20 16:35:48 -07:00
Michael Bolin
5746561428 chore: move types out of config.rs into config_types.rs (#1054)
`config.rs` is already quite long without these definitions. Since they
have no real dependencies of their own, let's move them to their own
file so `config.rs` can focus on the business logic of loading a config.
2025-05-20 11:55:25 -07:00
Michael Bolin
eb66b0324b Merge 55e5b5f87b into sapling-pr-archive-bolinfest 2025-05-20 11:32:48 -07:00
Michael Bolin
55e5b5f87b chore: move types out of config.rs into config_types.rs 2025-05-20 11:32:40 -07:00
Michael Bolin
d766e845b3 feat: experimental --output-last-message flag to exec subcommand (#1037)
This introduces an experimental `--output-last-message` flag that can be
used to identify a file where the final message from the agent will be
written. Two use cases:

- Ultimately, we will likely add a `--quiet` option to `exec`, but even
if the user does not want any output written to the terminal, they
probably want to know what the agent did. Writing the output to a file
makes it possible to get that information in a clean way.
- Relatedly, when using `exec` in CI, it is easier to review the
transcript written "normally," (i.e., not as JSON or something with
extra escapes), but getting programmatic access to the last message is
likely helpful, so writing the last message to a file gets the best of
both worlds.

I am calling this "experimental" because it is possible that we are
overfitting and will want a more general solution to this problem that
would justify removing this flag.
codex-rs-68e94c8c08943e1d4a53bd7987e319ba7dbffb74-1-rust-v0.0.2505191609
2025-05-19 16:08:18 -07:00
Michael Bolin
b27b9819d9 Merge 25e9684795 into sapling-pr-archive-bolinfest 2025-05-19 16:02:45 -07:00
Michael Bolin
25e9684795 feat: add --output-last-message flag to exec subcommand 2025-05-19 16:02:39 -07:00
Michael Bolin
ba700a2a17 merge commit for archive created by Sapling 2025-05-19 15:53:59 -07:00
Michael Bolin
89a37b1d35 feat: add --output-last-message flag to exec subcommand 2025-05-19 15:53:52 -07:00
Michael Bolin
937b29bfe8 Merge 921beff71a into sapling-pr-archive-bolinfest 2025-05-19 15:50:39 -07:00
Michael Bolin
921beff71a feat: add --output-last-message flag to exec subcommand 2025-05-19 15:50:32 -07:00