sandbox NextJS build goes for 20min+

Resolved 💬 2 comments Opened Mar 5, 2026 by henningpokriefke Closed Apr 24, 2026

What version of the Codex App are you using (From “About Codex” dialog)?

26.303.1606 (806)

What subscription do you have?

$200

What platform is your computer?

Darwin 25.1.0 arm64 arm

What issue are you seeing?

When codex tries to make a build "next build" that normally takes <20s it gets stale. I am using a turborepo with 3 NextJS applications and it happens for all of them.
It happens ONLY in the sandbox environment (when codex did not ask me (i am using standard permissions))

<img width="763" height="263" alt="Image" src="https://github.com/user-attachments/assets/18527f1b-1368-406a-8e4d-29e1f6bda952" />

Would be fixable with a e.g. standard timeout or possibility to skip that without stopping the agent.

Normal output would be (gets stale after 2nd line):

[...]
▲ Next.js 16.1.6 (Turbopack)

[MDX] generated files in 19.385582999999997ms
  Creating an optimized production build ...
✓ Compiled successfully in 7.1s
✓ Finished TypeScript in 1730.7ms    
✓ Collecting page data using 13 workers in 335.4ms    
[...]

What steps can reproduce the bug?

  • Setup Turborepo (might not be necessary but is my case and have not tested otherwise)
  • 1. let it run a task where it needs to build a NextJS App "next build" in a sandbox (See it failing here)
  • 2. Tell codex explicitly that he should ask about building outside of sandbox (See it succeeding here)

What is the expected behavior?

Building NextJS in under 20s.

Additional information

_No response_

View original on GitHub ↗

2 Comments

happyCodingHyy · 5 months ago

Can confirm this on my side as well.

I’m seeing the same behavior on one specific machine:

  • With sandbox enabled, next build becomes extremely slow / appears to stall (20+ minutes).
  • Outside sandbox, the same project finishes in under 20 seconds.

So far this is machine-specific for me (not all of my computers are affected). Happy to provide more environment details
or logs if that helps.

karlhorky · 28 days ago

@henningpokriefke @happyCodingHyy did either of you get this resolved?

I have been experiencing similar next build hangs while sandboxed.

Even just getting Next.js builds within a sandbox to exit with a helpful error would be enough.

For now I'm doing this hacky thing to exit in my scripts if next build is being run inside the agent sandbox:

// Fail fast in AI agent sandboxes to avoid hanging in next build
// - https://github.com/openai/codex/issues/18895#issuecomment-5132506377
if (process.env.CODEX_CI || process.env.CLAUDECODE) {
  await new Promise<void>((resolve, reject) => {
    const server = createServer();
    server.once('error', (error) => {
      reject(
        new Error(
          'AI agent sandbox detected - run `next build` outside the sandbox',
          { cause: error },
        ),
      );
    });
    server.listen(0, '127.0.0.1', () => {
      server.close(() => resolve());
    });
  });
}

Maybe it should be resolved on the Next.js side... cc @gaojude because I saw you also opened a similar issue:

  • #2641

There's also another (still open) issue that shows next build hanging within Codex CLI: