Uh oh!
There was an error while loading. Please reload this page.
fix: prevent shell commands from killing all Node.js processes - #25762
fix: prevent shell commands from killing all Node.js processes#25762Xelson431 wants to merge 1 commit into
Conversation
OpenCode is built on Node.js (node.exe). Running commands like 'taskkill /F /IM node.exe', 'killall node', 'pkill node', or 'Get-Process node | Stop-Process' crashes the AI assistant itself. This change adds defense in depth: 1. System prompt guard: Injects a critical safety reminder into the environment prompt for all models, instructing the AI never to run broad Node process-killing commands. 2. Shell tool prompt guard: Adds the same safety rule to the bash/shell tool description so the AI sees it every time the tool is invoked. 3. Runtime command guard: Validates shell commands before execution in ShellTool and throws a clear error if a dangerous pattern is detected. Fixes the immediate crash vector while keeping legitimate per-PID kills and project-scoped stop commands (npm stop, pm2 stop) allowed.
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes#7950
Type of change
What does this PR do?
OpenCode is built on Node.js (
node.exe). When the AI runs commands liketaskkill /F /IM node.exe,killall node,pkill node, orGet-Process node | Stop-Process, it kills its own process and immediately crashes the assistant.This PR adds defense in depth with three layers:
Safer alternatives like targeting a specific PID (
kill 12345) or using project-scoped stop commands (npm stop,pm2 stop <name>) remain unaffected.How did you verify your code works?
Tested locally on Windows:
taskkill /F /IM node.exeare blocked before executionkillall node,pkill node,Get-Process node | Stop-Process) are also rejectedAlso reproduced the original issue before applying the fix, where killing all Node processes terminated the active OpenCode session.
Screenshots / recordings
N/A — this is not a UI change.
Checklist