Description
The run_command tool fails on Windows with error spawn powershell.exe ENOENT when the system PATH environment variable is corrupted or incomplete, preventing the agent from executing shell commands.
Environment
- OS: Windows 10/11
- Node.js: v22.14.0
- Electron: (bundled version)
- Affected Tool:
run_command (bash-tool.ts)
Root Cause
The tool uses child_process.exec() with shell: 'powershell.exe', which relies on the system PATH to locate PowerShell. When:
- PATH is corrupted or empty
- Electron doesn't inherit system PATH properly
- Application runs in restricted environment
The error occurs: Error: spawn powershell.exe ENOENT
Steps to Reproduce
- Corrupt or clear PATH environment variable
- Start LocalDesk application
- Ask agent to execute any command (e.g., "list files in current directory")
- Agent calls
run_command tool
- Error:
spawn powershell.exe ENOENT
Current Code (bash-tool.ts)
const { stdout, stderr } = await execAsync(finalCommand, {
cwd: context.cwd,
maxBuffer: 10 * 1024 * 1024,
shell: isWindows ? 'powershell.exe' : undefined, // ❌ Fails if not in PATH
windowsHide: true,
encoding: 'utf8',
env: { ...process.env, PYTHONIOENCODING: 'utf-8' }
});
Proposed Solution
Use full path to PowerShell by leveraging the SystemRoot environment variable, which is more reliable than PATH:
// Fix for Windows: use full path to PowerShell if needed
const windowsShell = isWindows
? process.env.SystemRoot
? `${process.env.SystemRoot}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`
: 'powershell.exe' // Fallback to PATH if SystemRoot unavailable
: undefined;
const { stdout, stderr } = await execAsync(finalCommand, {
cwd: context.cwd,
maxBuffer: 10 * 1024 * 1024,
shell: windowsShell, // ✅ Uses full path
windowsHide: true,
encoding: 'utf8',
env: { ...process.env, PYTHONIOENCODING: 'utf-8' }
});
Benefits
✅ Reliability: Works even with corrupted PATH
✅ Compatibility: SystemRoot is a standard Windows environment variable (usually C:\Windows)
✅ Fallback: If SystemRoot is unavailable, falls back to original behavior
✅ No breaking changes: Maintains compatibility with existing installations
Alternative Approaches Considered
1. Use pwsh.exe (PowerShell Core)
shell: isWindows ? 'pwsh.exe' : undefined
❌ Rejected: Requires PowerShell 7+ installation, not available on all systems
2. Use cmd.exe instead
shell: isWindows ? 'cmd.exe' : undefined
❌ Rejected: cmd.exe has different syntax and encoding issues, would break existing commands
3. Search multiple locations
const powershellPaths = [
'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe',
'C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe',
'powershell.exe'
];
❌ Rejected: Overcomplicated, SystemRoot approach is cleaner
Testing
Tested scenarios:
- ✅ Normal Windows installation with intact PATH
- ✅ Windows with corrupted PATH
- ✅ Electron launched without inheriting system environment
- ✅ Restricted user environment
All scenarios work correctly with the proposed fix.
Files to Modify
src/electron/libs/tools/bash-tool.ts (lines 47-49)
Implementation
The fix has been implemented and tested. Ready for PR or direct commit.
Related Issues
- Windows environment variables reliability
- Electron environment inheritance on Windows
- Cross-platform shell command execution
Additional Notes
This issue is Windows-specific. macOS and Linux use default shell resolution and are not affected.
Description
The
run_commandtool fails on Windows with errorspawn powershell.exe ENOENTwhen the system PATH environment variable is corrupted or incomplete, preventing the agent from executing shell commands.Environment
run_command(bash-tool.ts)Root Cause
The tool uses
child_process.exec()withshell: 'powershell.exe', which relies on the system PATH to locate PowerShell. When:The error occurs:
Error: spawn powershell.exe ENOENTSteps to Reproduce
run_commandtoolspawn powershell.exe ENOENTCurrent Code (bash-tool.ts)
Proposed Solution
Use full path to PowerShell by leveraging the
SystemRootenvironment variable, which is more reliable than PATH:Benefits
✅ Reliability: Works even with corrupted PATH
✅ Compatibility:
SystemRootis a standard Windows environment variable (usuallyC:\Windows)✅ Fallback: If
SystemRootis unavailable, falls back to original behavior✅ No breaking changes: Maintains compatibility with existing installations
Alternative Approaches Considered
1. Use
pwsh.exe(PowerShell Core)❌ Rejected: Requires PowerShell 7+ installation, not available on all systems
2. Use
cmd.exeinstead❌ Rejected:
cmd.exehas different syntax and encoding issues, would break existing commands3. Search multiple locations
❌ Rejected: Overcomplicated,
SystemRootapproach is cleanerTesting
Tested scenarios:
All scenarios work correctly with the proposed fix.
Files to Modify
src/electron/libs/tools/bash-tool.ts(lines 47-49)Implementation
The fix has been implemented and tested. Ready for PR or direct commit.
Related Issues
Additional Notes
This issue is Windows-specific. macOS and Linux use default shell resolution and are not affected.