You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: execute (Code Mode) runtime has no CommonJS require() — require('fs') throws ReferenceError #56811
The execute tool's confined Code Mode runtime does not expose CommonJS require(). Any snippet that calls require('fs'), require('child_process'), etc. fails with:
ReferenceError: Unknown identifier 'require'. (line 1, col 12)
The tool description states: "Imports, direct filesystem access, and timers are unavailable; all other external access goes through tools." That is only partially accurate — fetch is available, but require() is not available at all, so even pure logic that happens to load a module cannot run. Users are left guessing which globals exist.
Impact
Many realistic scripting workflows in Code Mode are blocked outright (reading files, spawning processes, path math). The gap is undocumented and not discoverable from the tool description.
Suggested fix
Either:
expose a minimal require() shim for node built-in modules (fs, path, child_process, os), or
document the limitation clearly in the tool description and ship a stable tools.* filesystem/process helper so users are not left guessing.
changed the title [-][Bug]: execute (Code Mode) runtime has no CommonJS — throws ReferenceError[/-][+][Bug]: execute (Code Mode) runtime has no CommonJS require() — require('fs') throws ReferenceError[/+]on Oct 18, 2026
This is intended behaviour, not a bug. Code Mode's execute runs in OpenCode's own sandboxed JavaScript interpreter, not in Node. It deliberately has no module system (require/import), so access to files and processes goes through the tools in the Code Mode catalog, where OpenCode's permissions still apply. The tool description already says "Imports, direct filesystem access, and timers are unavailable", which is why require shows up as an unknown identifier.
I'm treating this as a feature request with two possible directions:
a require shim for Node built-ins (fs, path, child_process, os) inside Code Mode, or
a clearer description of which globals are available, plus reliable filesystem/process helpers under tools.*.
Maintainers will consider it. In the meantime, the regular file and shell tools (outside execute, or through tools.* when they're listed in the Code Mode catalog) are the way to read files and run commands.
Activity
[-][Bug]: execute (Code Mode) runtime has no CommonJS — throws ReferenceError[/-][+][Bug]: execute (Code Mode) runtime has no CommonJS require() — require('fs') throws ReferenceError[/+]opencode-agent commentedon Oct 18, 2026
Thanks for the detailed write-up, @dimahc!
This is intended behaviour, not a bug. Code Mode's
executeruns in OpenCode's own sandboxed JavaScript interpreter, not in Node. It deliberately has no module system (require/import), so access to files and processes goes through the tools in the Code Mode catalog, where OpenCode's permissions still apply. The tool description already says "Imports, direct filesystem access, and timers are unavailable", which is whyrequireshows up as an unknown identifier.I'm treating this as a feature request with two possible directions:
requireshim for Node built-ins (fs,path,child_process,os) inside Code Mode, ortools.*.Maintainers will consider it. In the meantime, the regular file and shell tools (outside
execute, or throughtools.*when they're listed in the Code Mode catalog) are the way to read files and run commands.Related issues and PRs:
fetchwas added to Code Modefetchon the webfetch permissionUnknown identifiererror in Code Mode