Question

npm install fails inside Codex with ENOTFOUND registry.npmjs.org

Solved · 199 viewsasked by tomvibes

Asked Codex to add zod to my project. It runs npm install zod and gets:

Then it tries three other ways to install it, all fail, and it ends up writing its own validation functions instead. My internet is fine, npm install works in my own terminal.

What I’ve tried

Restarted Codex, restarted my laptop, cleared the npm cache. Same error only inside Codex.

Comment

2 answers

Marked as helpful by the asker
deploydan

Your internet is fine, Codex's is not. In the default workspace-write sandbox, network access is off. That is on purpose: a model that can reach the internet can also send your code or keys somewhere.

Options, safest first:

  1. Run npm install zod yourself in your own terminal and tell Codex it is installed. Takes five seconds.
  2. Let it ask: when it hits the sandbox it can request to run the command outside it, and you approve that one command.
  3. Turn network on for the sandbox in ~/.codex/config.toml:
[sandbox_workspace_write]
network_access = true

I stick to 1. The bigger lesson is the last part of your question: when it cannot install something, it quietly writes its own version. Tell it in AGENTS.md to stop and ask instead.

Comment
sam_builds

Same thing happened to me with a date library. It wrote 200 lines of date code. Option 1 is the way.

Comment