How to Stop Codex Loops in Dockerized Node.js: Fix 'Continuous npm build retry loop when Docker volume mounting lockfiles'
what is happening
Codex can become stuck repeatedly running `npm install`, `npm run build`, or `docker build` when volume-mounted lockfiles or dependency mismatches cause identical build failures. Instead of isolating the filesystem or dependency issue, the agent retries the same build sequence, consuming tokens without making progress. Aligning lockfiles, reducing build scope, and enforcing retry limits prevents these recursive build loops.
manual fix
Verify that the host and container use the same lockfile and package manager, avoid conflicting volume mounts for dependency files, and reproduce the build manually before allowing another automated retry. If Codex repeatedly executes identical `npm` or `docker build` commands without changing the environment, stop the agent, reset context, and restart with a focused build task.
capping calls & killing loops automatically
if you want to prevent runaway background processes from burning through API credits, you can set budget caps and loop limits directly in terminal using guardrail.
npx @neatproxy/guardrail --preset codex --target docker-ts --max-budget 10.00 --loop-cap 3
running into a different edge case? join us at neat to share logs or ask the team.