Skip to content

fix(chat): run Codex threads in the native sandbox workspace - #1089

Open
finallylly wants to merge 2 commits into
Tencent:mainfrom
finallylly:codex/fix-codex-native-cwd
Open

finallylly wants to merge 2 commits into
Tencent:mainfrom
finallylly:codex/fix-codex-native-cwd

Conversation

@finallylly

Copy link
Copy Markdown

What changed

On macOS, a Codex conversation workspace using the native (seatbelt) sandbox could not write to its working directory. Relative commands such as git clone or mkdir failed with Operation not permitted, and the agent fell back to the system temp directory.

The runtime already starts the CLI in the run workspace on seatbelt, because seatbelt cannot map <root>/ws onto it (#947). The Codex app-server adapter, however, always sent cwd=<root>/ws on thread/start and thread/resume. Codex therefore ran shell commands in the conversation cache directory, which the seatbelt profile does not allow writing to.

The adapter now sends cwd: ".", so the thread follows the process working directory selected by the runtime for each sandbox. The cwd is also sent on resume: without it, Codex keeps the directory recorded when the thread started, so a platform-mode thread handed to a workspace would stay in <root>/ws.

Scope

  • Platform core / API / runner
  • Public adapter / deployment
  • Classic
  • Portable
  • Shared behavior contract
  • Installer / CLI
  • Documentation only

Compatibility

Only the Codex engine is affected. Its effective cwd changes only for macOS seatbelt workspaces. Platform mode, review-only calls, Docker, Linux bwrap and runner execution all start the CLI in <root>/ws, so "." resolves to the same directory as before. A runner that predates the seatbelt working-directory change keeps its previous behavior. No schema or runner protocol changes.

The fix relies on Codex resolving a relative cwd against the app-server process directory. This was checked with Codex CLI 0.150.0, 0.169.0 and 0.170.0: thread/start and thread/resume with cwd: "." both use the process directory, while thread/resume without cwd keeps the originally recorded directory. Unit tests do not run a real Codex binary, so this should be rechecked when upgrading Codex.

Validation

Run on macOS (Apple silicon).

go test ./internal/httpapi -count=1                  # pass
go test ./internal/httpapi -run TestCodexAppServer   # pass; the new cwd assertions fail without the fix
go vet ./...                                         # pass
python3 scripts/check-public.py                      # pass
go test -p=2 ./... -count=1 -timeout=180s            # failures in cmd/agentflow, deploy, internal/engine (timeout),
                                                     # internal/gitwork, internal/runner, internal/runtime; deploy, engine,
                                                     # gitwork and runtime do not depend on internal/httpapi; the
                                                     # cmd/agentflow and internal/runner failures reproduce on main
                                                     # in this macOS environment (Linux-only systemd test, local git/xcrun)
bash scripts/scan-secrets.sh                         # not run as-is: the script downloads the Linux x64 gitleaks binary;
                                                     # ran gitleaks v8.30.1 built locally with .gitleaks.toml on the same
                                                     # file export: no leaks found
bash local/scripts/validate.sh                       # not run (LoopForge Local not changed)
bash local/scripts/smoke-install.sh                  # not run (LoopForge Local not changed)
bash local/scripts/e2e.sh                            # not run (LoopForge Local not changed)

Manual check on macOS with a native sandbox and Codex: in a new Codex conversation workspace, pwd reports the run workspace, and mkdir and git clone succeed there without falling back to a temp directory.

Safety

  • I did not include credentials, internal endpoints, production data, or organization-specific infrastructure.
  • I preserved user files and unrelated changes.
  • I updated generated Classic host bundles when applicable.
  • I documented third-party content and licensing changes when applicable.

The Codex app-server adapter always sent cwd=<root>/ws on thread/start
and thread/resume. On macOS seatbelt there is no mount namespace, so the
runtime starts the CLI in the run workspace instead, and <root>/ws is not
writable there. Codex then ran shell commands in the cache directory and
relative writes such as git clone or mkdir failed with "Operation not
permitted".

Send cwd="." so the thread follows the process working directory chosen
by the runtime for each sandbox. Platform mode, Docker, bwrap and runner
execution still start the CLI in <root>/ws, so they are unchanged. The
cwd is also sent on resume, because Codex otherwise keeps the directory
recorded when the thread started.
@finallylly

Copy link
Copy Markdown
Author

补充一下中文说明,方便 review:

问题:macOS 上使用 native(seatbelt)沙箱的 Codex 对话工作区无法写入当前目录,git clone、mkdir 等相对路径操作会报 Operation not permitted,Agent 只能退到系统临时目录。

原因:#947 已经让 seatbelt 下的 CLI 进程直接运行在 run workspace 中,但 Codex app-server 适配器在 thread/start / thread/resume 时仍固定传 cwd=<root>/ws,而 seatbelt 规则不允许写这个目录。

修改:改为传 cwd: ".",让 Codex 跟随运行时为各沙箱设置的进程目录。平台模式、Docker、Linux bwrap 和执行机器的进程目录本来就是 <root>/ws,行为不变;实际变化只发生在 macOS seatbelt。thread/resume 也需要显式传,否则 Codex 会沿用线程创建时记录的旧目录。

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.

1 participant