Skip to content

Respect Codex sandbox config and permission profiles - #8145

Open
ymichael wants to merge 4 commits into
mainfrom
bb/8008-codex-provider-overrides-sandbox-config-net-thr_yyyfuh6ibm
Open

ymichael wants to merge 4 commits into
mainfrom
bb/8008-codex-provider-overrides-sandbox-config-net-thr_yyyfuh6ibm

Conversation

@ymichael

@ymichael ymichael commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The Codex provider overrode sandbox rules that an admin or user set in Codex's own configuration (#8008):

  • Network. Every workspace turn sent networkAccess: true in its per-turn sandboxPolicy (toWorkspaceWriteCodexSandboxPolicy). That overrides every Codex config layer and requirements.toml, so "network off" had no effect.
  • Permission profiles. When Codex's config or requirements set a custom permission profile as the default (default_permissions), bb replaced it with its own legacy sandbox mode and per-turn sandbox policy. That dropped the profile's filesystem and network rules.

The credentials half of #8008 (thread env, including launch tokens, copied into shell_environment_policy.set past exclude) landed in #8075.

What changed

  • plugins/provider-codex/src/bridge/bridge.ts, session-params.ts: when a session starts, bb reads Codex's config (config/read with origins) and requirements (configRequirements/read).
    • If any config layer sets sandbox_workspace_write.network_access, or requirements manage the network, bb uses Codex's value.
    • If Codex says nothing, network stays on, so commands can reach the local bb server and the bb CLI keeps working.
    • If the reads fail, network is off.
  • Profile mode. When Codex's config or requirements make a custom profile the default, bb selects that profile through Codex's permissions field on thread construction and on turns, instead of sending a sandbox policy.
    • Workspace permissions select the profile, and bb adds the git paths a linked worktree needs to the profile's filesystem table.
    • Full access selects :danger-full-access only when permissionProfile/list says requirements allow it. Otherwise the turn fails and asks for workspace permissions. Codex 0.136-0.141 list profiles without allowed; bb then selects :danger-full-access and leaves enforcement to Codex.
    • Sessions without a custom profile keep the sandbox-policy path.
  • translator.ts: handles the profile-mode turn settings.
  • skills/codex-provider/SKILL.md documents the rules above.
  • packages/provider-bridge-protocol/src/testing/replay-provider-child.mjs: no committed Codex recording has the two new session-start reads. The replay child now answers them, when the script does not expect them, as a Codex config that sets nothing, the same way it answers Pi's model-selection requests that older recordings lack (Build every provider CLI's environment with one builder #7722). Without this, every Codex parity cell and the settings-steer/settings-follow-up scenario cells timed out.
  • No wire change and no HOST_DAEMON_PROTOCOL_VERSION bump.

How you verified

  • New and updated tests in session-params.test.ts, bridge.session-signature.test.ts and translator.test.ts cover network resolution from config and requirements, the failed-read fallback, profile selection with worktree roots, and the full-access gate.
  • session-params.test.ts parses a profile list without allowed (the Codex 0.136-0.141 shape, checked against real 0.136/0.140/0.141 binaries). Before the fix, that list failed thread/start with "unexpected permissionProfile/list result".
  • replay-provider-child.test.ts replays a recording with a later model-catalog config/read while the bridge sends the sandbox reads first. It fails without the replay change and passes with it.
  • pnpm exec turbo run typecheck lint test --filter=bb-plugin-provider-codex --filter=@bb/provider-parity --filter=@bb/provider-bridge-protocol: pass (provider-parity 80/80, all replays, no cache). lint:type-aware and apps/server/test/skills/shipped-skills-quality.test.ts pass.
  • Manual before/after QA was run on a pnpm start:worktree server with Codex 0.171 and project-level .codex/config.toml test repos. Those notes were not kept, so the review on this PR re-runs them.

Fixes #8008

AGENT GENERATED

🤖 Generated with Claude Code

ymichael added a commit that referenced this pull request Nov 24, 2026
…8075)

## Human comments

## What was wrong

The Codex bridge copied every thread environment variable into
`shell_environment_policy.set.*` in the `thread/start` and
`thread/resume` config (`buildShellEnvironmentPolicyConfig` in
`plugins/provider-codex/src/session-params.ts`). This included plugin
contributions such as the Account Pooler's `CODEX_POOL_AUTH_TOKEN` and
`BB_ACCOUNT_POOL_PARENT_TOKEN`, and `GH_TOKEN`. Codex applies `set`
after `inherit` and `exclude`, so an admin's
`shell_environment_policy.exclude = ["*TOKEN*"]` could not keep these
values out of sandboxed commands (#8008, part 2). The `set` copy dates
from when one app-server served several bb threads (901aebd). Now
each bb thread starts its own app-server, and its process environment is
the thread environment (`spawnChildConnection`, also on every rebuild
from #6939). The copy therefore only overrode the user's or admin's
Codex policy.

## What changed

- `plugins/provider-codex/src/session-params.ts`: `buildCodexConfig` no
longer copies the thread environment into
`shell_environment_policy.set`. Codex's own `shell_environment_policy`
decides which variables from the app-server environment reach commands.
bb still forces its non-secret context variables through `set`
(`BB_THREAD_ID`, `BB_PROJECT_ID`, `BB_ENVIRONMENT_ID`,
`BB_THREAD_STORAGE`, `BB_CLI`, `BB_SERVER_URL`, `BB_HOST_DAEMON_PORT`),
so the `bb` CLI works under any policy. With Codex's default policy
(inherit all), commands get the same variables as before.
- `plugins/provider-codex/skills/codex-provider/SKILL.md`: documents how
the thread environment reaches Codex commands and how an `exclude`
filters it.
- Tests: `session-params.test.ts` asserts that only bb's context
variables appear in `shell_environment_policy`, and no tokens or project
variables. `bridge.session-signature.test.ts` now asserts that a rotated
or removed variable reaches the relaunched app-server's process
environment and not the session config. `fake-codex-app-server.mjs` logs
`CODEX_SIGNATURE_TEST_*` variables at launch for that assertion.
- Behavior change for strict Codex policies: with `inherit = "core"` or
`"none"`, or a matching `exclude`, commands no longer get `GH_TOKEN`,
plugin contributions or project variables, because bb no longer forces
them through `set`. bb's context variables above are still forced, so
`bb` CLI calls keep working. Codex's default policy is not affected.
- No wire change, no `HOST_DAEMON_PROTOCOL_VERSION` bump, no plugin API
change.
- Not changed, left for a maintainer decision:
- Part 1, `networkAccess: true` in `toWorkspaceWriteCodexSandboxPolicy`:
this has been there since the first Codex adapter (c7a5bd2), next to
`readOnly` with `networkAccess: false`. Codex's Linux sandbox with
network off also blocks loopback, so `bb` CLI calls from sandboxed
commands would fail (checked with `codex sandbox` and `curl` to
127.0.0.1: `000` with network off, `200` with network on). The
`workspaceWrite` schema requires `networkAccess`, so the only way to
defer to Codex is to stop sending a per-turn `sandboxPolicy`. Options:
(a) keep it and document that the workspace modes allow network; (b) add
a Codex provider setting, like Claude Code's `sandboxEnabled`, that
leaves the sandbox to Codex's config and `requirements.toml`; (c) turn
network off and route it through approval, like Claude's sandbox, which
allows loopback only.
- With Codex's default policy, sandboxed commands still see the hub
token. `BB_ACCOUNT_POOL_PARENT_TOKEN` reaches agent commands on purpose
so that a nested bb server can use the parent's pool (#3654). Claude
Code threads get it the same way, and `CODEX_POOL_AUTH_TOKEN` has the
same value. Whether routed threads should pass that token by default is
a product decision.
  - The login-shell PATH order note.

## How you verified

- The new `session-params.test.ts` and
`bridge.session-signature.test.ts` assertions fail on origin/main (2
failed, 80 passed) and pass with the change.
- End to end with Codex CLI 0.171.0: a real `codex app-server`, started
with bb's `resolveAppServerLaunch`, `buildCodexConfig` and
`toCodexPermissionSettings`, a scratch `CODEX_HOME`, a fake Responses
server as the hub, and a fake pool token. An accept-edits workspace turn
ran `env` in the workspace-write sandbox, and a write outside the
workspace was denied.
- With `exclude = ["*TOKEN*"]` in config.toml: origin/main showed
`BB_ACCOUNT_POOL_PARENT_TOKEN` and `CODEX_POOL_AUTH_TOKEN` in the
command environment. With this change the command environment has no
TOKEN variables.
- With Codex's default policy, both builds pass both variables (Codex
inherits all).
- In every run the hub received `x-bb-account-pool-token` on 2/2 model
requests, and `BB_THREAD_ID` and `PLUGIN_API_URL` reached the command.
- Live check on a `pnpm start:worktree` instance with Codex 0.171,
reading raw command output from the event log:
- Project `.codex/config.toml` with `exclude = ["*TOKEN*"]` and a
project variable `QA_FAKE_TOKEN`: main passes `QA_FAKE_TOKEN` to the
command; this branch does not, and `$BB_CLI status` works.
- `inherit = "core"`: commands get only the bb context variables (no
project variables or tokens), and `$BB_CLI status` works.
- `pnpm exec turbo run typecheck test lint
--filter=bb-plugin-provider-codex --force`: pass (625 tests).
- `pnpm exec turbo run test --filter=@bb/provider-parity --force`: pass
(80 tests).
- `apps/server/test/skills/shipped-skills-quality.test.ts`: pass.

Part of #8008. The network-access half and Codex permission profiles are
in #8145.

> AGENT GENERATED

---------

Co-authored-by: Michael Yong <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael and others added 3 commits November 25, 2026 19:56
Workspace turns hard-coded networkAccess: true in the per-turn sandbox
policy, which overrides every Codex config layer and admin requirements.
bb now reads Codex's config (config/read with origins) and requirements
(configRequirements/read) when a session starts. It keeps network on only
when Codex says nothing about it, and uses Codex's own value when a config
layer sets sandbox_workspace_write.network_access or requirements manage
permission profiles or the network. If the reads fail, network is off.

Refs #8008

Co-Authored-By: Claude Opus 5.5 <[email protected]>
When Codex's config or requirements make a custom permission profile the
default, bb used to replace it with its own legacy sandbox mode and
per-turn sandbox policy, dropping the profile's filesystem and network
rules. bb now selects the profile through Codex's `permissions` field on
thread construction and turns. It adds linked-worktree git roots to the
profile's filesystem table, and selects :danger-full-access for full
scope only when permissionProfile/list says requirements allow it.
Sessions without a custom profile keep the sandbox-policy path.

Refs #8008

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Codex bridge now reads config/read (with cwd) and
configRequirements/read before thread/start. No committed Codex
recording has those requests. In the scenario cells the live
config/read lookahead-matched the recording's later model-catalog
config/read, skipping thread/start, model/list and turn/start, so
settings-steer and settings-follow-up timed out. In the parity cells the
generic {} answer after the stall failed the bridge's result schema and
session construction failed, so every Codex cell timed out.

The replay child now answers these reads, when the script does not
expect them, as a Codex config that sets nothing, the same way it
answers Pi's model-selection requests that older recordings lack.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/8008-codex-provider-overrides-sandbox-config-net-thr_yyyfuh6ibm branch from dfddbf4 to 92d3a76 Compare November 26, 2026 04:15
Codex 0.136-0.141 list permission profiles without `allowed`. bb required
it, so a session in a repo with a custom default profile failed to start on
those versions. A missing `allowed` now leaves the full-access decision to
Codex, which enforces its requirements at turn start.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexburlis added a commit to alexburlis/omnyo that referenced this pull request Nov 26, 2026
Record the upstream PRs, revisions, contributors, and Omnyo integration
commits for merge d2a24ac in docs/upstream-credits.md.

Original-PR: get-bb/bb#7663
Original-Commit: get-bb/bb@1737a03
Original-Author: rufi
Original-PR: get-bb/bb#8055
Original-Commit: get-bb/bb@651ae20
Original-Author: Jake Lancaster
Original-PR: get-bb/bb#8075
Original-Commit: get-bb/bb@511e1ed
Original-Author: Jake Lancaster
Original-Co-Author: Michael Yong
Original-Co-Author: Claude Opus 5.5
Original-PR: get-bb/bb#8096
Original-Commit: get-bb/bb@775090b
Original-Author: Michael Yong
Original-Co-Author: Claude Opus 5.5
Original-PR: get-bb/bb#8145
Original-Commit: get-bb/bb@8de6711
Original-Commit: get-bb/bb@0d3db49
Original-Commit: get-bb/bb@92d3a76
Original-Commit: get-bb/bb@6705422
Original-Author: Michael Yong
Original-Co-Author: Claude Opus 5.5
Original-PR: get-bb/bb#8171
Original-Commit: get-bb/bb@b56ed04
Original-Author: Jake Lancaster
Original-PR: get-bb/bb#8238
Original-Commit: get-bb/bb@2a9a142
Original-Author: SawyerHood
Original-PR: get-bb/bb#8247
Original-Commit: get-bb/bb@ba4ae22
Original-Author: Salem
Original-Co-Author: Claude Opus 5.5
Original-PR: get-bb/bb#8259
Original-Commit: get-bb/bb@96f40a9
Original-Author: SawyerHood
Original-PR: get-bb/bb#8263
Original-Commit: get-bb/bb@141e40a
Original-Author: mk
Original-PR: get-bb/bb#8266
Original-Commit: get-bb/bb@84e20e9
Original-Author: ILIA GOLUBEV

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex provider overrides sandbox config: networkAccess:true hard-coded; Account Pooler token reaches sandboxed commands via shell_environment_policy.set

1 participant