macOS sandbox: Turbopack next build completes work but does not exit, leaving .next/lock open
What version of Codex CLI is running?
codex-cli 0.118.0
What subscription do you have?
ChatGPT Plus
Which model were you using?
gpt-5.4
What platform is your computer?
macOS 26.4.1 (Build 25E253), Darwin 25.4.0, arm64
What terminal emulator and version are you using (if applicable)?
Codex in VS Code / extension-host environment on macOS
What issue are you seeing?
In the Codex macOS sandbox, next build for a Next.js 16.2.0 app using Turbopack appears to complete the build work but the process does not exit cleanly.
Observed behavior inside Codex:
npm run buildreachesCreating an optimized production build ...- the process then remains alive in sleep state with ~0% CPU instead of exiting
- the process keeps
.next/lockopen - a subsequent build reports
Another next build process is already running. - if I kill the stuck build and rerun with webpack instead of Turbopack, the build exits normally
Important detail: Next's own trace output indicates the build work actually finished. In .next/trace-build, next-build completed in about 9 seconds, including static generation and trace collection. The hang appears to be in process teardown / exit, not compilation.
The same project builds successfully outside Codex on the same machine, so this looks environment-specific to the Codex macOS sandbox rather than an application bug.
What steps can reproduce the bug?
- Use Codex on macOS in the default sandboxed environment.
- Open any Next.js 16.2.0 app that uses the default Turbopack production build.
- Run
npm run build. - Wait for the build to reach
Creating an optimized production build .... - Observe that the process remains alive after the build artifacts and
.next/trace-buildindicate completion. - Attempt a second build and observe
Another next build process is already running.
What is the expected behavior?
After the build work completes, next build should exit normally.
Additional information
Relevant environment details observed from inside Codex:
CODEX_SANDBOX=seatbeltCODEX_SANDBOX_NETWORK_DISABLED=1TERM=dumbELECTRON_RUN_AS_NODE=1
What I tested:
- unsetting the
CODEX_*environment variables did not fix the hang in this environment NEXT_TELEMETRY_DISABLED=1 npm run buildstill hungnpm exec next build -- --webpackcompleted successfully and exited normallylsof -p <pid>for the hung process showed.next/lockstill open and no child processes remaining
This makes Turbopack + Codex macOS sandbox teardown the most likely problem area.
3 Comments
@gaojude @sampoder should this be reported + fixed within Next.js? Do you know why
next buildhangs inside Codex CLI by default?I've been encountering this for a while and I thought it was the fault of Codex, but maybe it should be fixed in Next.js?
For our app, it also appears to only affect Turbopack, not webpack.
---
For now I'm doing this hacky thing to exit in my scripts if
next buildis being run inside the agent sandbox:Hi @karlhorky & @ohcedar! Thanks for sharing! This appears to be an issue with Webpack loaders in Turbopack and Codex's not allowing local binding by default (which we depend on). You can fix this by configuring
allow_local_bindingto be true in your Codex configuration: https://learn.chatgpt.com/docs/permissions#local-and-private-networks.If you would like to not enable that by default, you can prompt your agent to ask for one-time permission when using
next buildAlternatively, with newer versions of Next.js / Turbopack we have fixed issues with this experimental worker threads option for loaders:
See https://github.com/vercel/next.js/pull/95281. You can use that to work around this limitation! However, in older versions, I wouldn't recommend this option as there used to be a memory safety bug.
Enabling allow_local_binding or using the newer runtime resolves the Turbopack hang.