Repository navigation
Open
Labels
area/harnessagentscope-harness (test/runtime support)bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed
Description
Description
When attempting to execute Shell commands via LocalFilesystemWithShell on Windows, the following exception occurs:
io.agentscope.harness.agent.filesystem.local.LocalFilesystemWithShell -- Command execution failed: Cannot run program "sh" (in directory "E:\agentscope\workspace\3846161173172182283"): CreateProcess error=2, 系统找不到指定的文件。
java.io.IOException: Cannot run program "sh" (in directory "E:\agentscope\workspace\3846161173172182283"): CreateProcess error=2, 系统找不到指定的文件。
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143)
...
The error occurs because Windows does not have the sh (Unix Shell) command available by default, causing the CreateProcess call to fail.
Steps to Reproduce
- Run the relevant code on a Windows system.
- Invoke
LocalFilesystemWithShell.execute()or useShellExecuteToolto run a Shell command. - Observe the console or logs for the above exception.
Expected Behavior
On Windows systems, the code should either:
- Automatically detect the OS and switch to an appropriate shell (e.g.,
cmdorPowerShell). - Provide clear instructions to the user about how to configure the shell environment.
Root Cause
- The code does not check the operating system type and defaults to using the Unix
shcommand. - There is insufficient cross-platform support for Windows environments.
Environment Information
- OS: Windows
- Working Directory:
E:\agentscope\workspace\3846161173172182283 - Related Modules:
LocalFilesystemWithShell,ShellExecuteTool
Suggested Solutions
- OS Detection: Before executing shell commands, detect the current operating system:
- On Windows, use
cmd /corPowerShellfor command execution. - On Unix/Linux/macOS, continue using
sh.
- On Windows, use
- Configurable Shell Path: Allow users to configure a custom shell path via settings or environment variables.
- Documentation: Clearly document that Windows users need to install a
sh-compatible environment (e.g., Git Bash, Cygwin) or use alternative cross-platform command execution methods.
Relevant Code/Logs
See the provided stack trace.
Additional Notes
If this is the first time running this feature on Windows, please consider adding cross-platform compatibility notes to the documentation to help other users avoid similar issues.
Metadata
Metadata
Assignees
Labels
area/harnessagentscope-harness (test/runtime support)bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed
Type
Projects
- StatusShow more project fieldsIn progress
Activity
wlgusqkr commentedon May 15, 2026
Hi, I'd like to work on this. Could it be assigned to me? Thanks!
zshs000 commentedon May 15, 2026
I think we can refer to pi's Windows compatibility approach:
Docs: https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/docs/windows.md
Key design points from pi:
shellPathinsettings.jsonAgentScope could adopt a similar design — add auto-detection logic in
LocalFilesystemWithShelland ashellPathconfig option inLocalFilesystemSpec.wlgusqkr commentedon May 20, 2026
I have analyzed the issue and put together an implementation plan. Since AgentScope Java currently doesn't have a global
settings.jsonsystem like the Pi project, I would love to get your feedback on a few design choices before I start writing the code.Here is my analysis and proposed approach:
1. Current Findings
LocalFilesystemWithShell(withinagentscope-harness), notShellCommandTool.ShellExecuteTooldelegates execution toAbstractSandboxFilesystem.execute(...).LocalFilesystemWithShell.execute(...)is called when using the default local filesystem mode orLocalFilesystemSpec.LocalFilesystemSpeconly supports fields likeexecuteTimeoutSeconds,maxOutputBytes,env,inheritEnv, andvirtualMode.settings.jsonconfiguration system yet.2. Proposed Implementation: Shell Selection Logic
For Unix/macOS, we keep the existing
sh -capproach. For Windows, we will implement a shell discovery logic with the following priority:shellPath(if provided)sh(if available inPATH)C:\Program Files\Git\bin\bash.exe)bash.exe(if available inPATH)shellPath.Depending on the detected shell, the
ProcessBuilderarguments will be adjusted:sh -c <command>bash -lc <command>3. Open Design Questions (Feedback Requested)
Before proceeding, I would like to get the maintainers' opinions on two main decisions:
Question 1: Where should we configure
shellPath?**Option A: Add directly to
LocalFilesystemSpec**Java(Pros: Fits existing config style, small scope. Cons: Requires users to explicitly configure
LocalFilesystemSpecinstead of using the default mode; placing local environment paths inside Java code can feel a bit awkward.)Option B: Add a dedicated config object (e.g.,
LocalShellConfig)Java
(Pros: Easily extensible for future shell types/args. Cons: Might be overkill for just this issue.)
.agentscope/settings.json)(Pros: Cleanest UX, users don't need to modify Java code for environment setup. Cons: Requires building a new global configuration system, expanding the scope of this PR significantly.)Question 2: Should we require a Bash-compatible shell on Windows?
Most commands generated by agents (e.g.,
ls -la,grep -R,export NODE_ENV=test) follow Unix semantics. These will likely fail or behave unexpectedly if executed incmd.exeorpowershell.exe.sh/bash. If not found, we throw a clear error guiding the user to install Git for Windows or setshellPath. This guarantees that agent commands execute consistently across platforms.powershell.exeandcmd.exeto the bottom of the discovery priority. This prevents the "Cannot run program" error on clean Windows machines, but we risk agents failing downstream due to command syntax errors.Could you let me know which approach you prefer for the
shellPathconfiguration and the PowerShell/cmd fallback? Once we decide, I'll submit a PR!wlgusqkr commentedon Jun 3, 2026
Hi @zshs000 , just a gentle ping on this!
To save you some time, I’ve summarized my previous analysis and the implementation plan below. Let me know if you have any thoughts on the options so I can start working on the PR. Thanks!
Summary: Windows Shell Execution Support in LocalFilesystemWithShell
1.Proposed Approach
I plan to implement shell discovery logic specifically for Windows. The discovery priority will be:
Explicit shellPath -> sh (in PATH) -> Git Bash default path -> bash.exe (in PATH).
If nothing is found, it will throw an exception. The ProcessBuilder arguments will automatically adjust based on the detected shell.
2.Open Design Questions (Feedback Needed)
Q1: Where should we configure shellPath?
Option A: Add directly to LocalFilesystemSpec. (Pros: Simple. Cons: Requires users to hardcode local environment paths inside Java code).
Option B: Add a dedicated LocalShellConfig object. (Pros: Extensible. Cons: Might be overkill for this specific issue).
Option C: Introduce a global .agentscope/settings.json. (Pros: Cleanest UX. Cons: Significantly expands the scope of this PR).
Q2: Should we strictly require a Bash-compatible shell on Windows?
Option 1 : Strict Bash compatibility. If not found, throw a clear error guiding the user to install Git Bash. This guarantees that Unix-style commands generated by agents execute consistently.
Option 2: Best-effort fallback to PowerShell/cmd. Prevents initial "Cannot run program" errors, but risks downstream syntax errors when agents generate Unix-specific commands.
zshs000 commentedon Jun 3, 2026
Hi @wlgusqkr , thanks for the ping!
Just to clarify - I'm not a maintainer of this project, I just shared some thoughts on this issue earlier 🙂 But here's my personal opinion as someone who suggested the Pi approach:
For Q1: I'd recommend Option A
Adding shellPath directly to LocalFilesystemSpec makes the most sense for this PR. It's simple, follows the existing configuration pattern, and keeps the scope focused. Option C (global settings.json) would be a great separate feature, but it's definitely out of scope for this fix.
For Q2: I strongly recommend Option 1
Strict Bash compatibility is the right approach here. As you mentioned, agents almost always generate Unix-style commands - falling back to PowerShell/cmd would just cause confusing downstream errors. Git Bash is very common for Windows developers, and a clear error message guiding users to install it is much better than silent failures.
Your implementation plan looks great! You might also want to ping the actual maintainers (@LearningGp ) for their official sign-off before you start the PR.
Good luck with this - looking forward to seeing Windows support land! 🚀
wlgusqkr commentedon Jun 3, 2026
@zshs000, thanks for clarifying and for the great feedback! I completely agree that Option A and Option 1 make the most sense for keeping the scope manageable and ensuring consistent behavior.
Hi @LearningGp , just pinging you as the maintainer to get your official thoughts. Would you be aligned with proceeding with Option A and Option 1 based on the summary above? Let me know if I have the green light to start working on the PR! Thanks.
LearningGp commentedon Jun 4, 2026
PTAL @chickenlj
ningmao-hlyz commentedon Nov 11, 2026
Since this has been idle since June:
mainnow falls back tocmd.exe /con Windows, so the crashin the report is gone, but the agreed design never landed. Every command is still forced through
cmd, where POSIX syntax (&&chains, quoting,ls-style commands) behaves differently from thesh -cthe same agent produces on Linux.I'm picking this up unless @wlgusqkr is still on it. Scope, following the Option A + Option 1
conclusion above:
LocalFilesystemSpec.shellPath(String)for an explicit shell (Option A).shonPATH-> Git Bash default install locations ->bash.exeonPATH->cmd.exe(today's behaviour, with a warning).-cfor POSIX shells,/cforcmd.exe,-Commandfor PowerShell, so an explicitshellPathworks for either family.One more thing I hit while testing this on Windows, which I will fix in the same change: when a
custom
envis set withinheritEnv=false,execute()clears the environment and keeps only thecaller's variables, so
PATHis gone and the shell starts but cannot resolve anything:A configurable shell is not much use if the child process cannot find its own tools, so the fix
restores the variables the OS needs to start a process (
PATH,SystemRoot,PATHEXT,COMSPEC,TEMP/TMPon Windows,HOME/LANGon POSIX) before applying the caller's overrides.feat(harness): let the local shell be configured instead of following…
feat(harness): let the local shell be configured instead of following…
feat(harness): let the local shell be configured instead of following…
feat(harness): let the local shell be configured instead of following…
feat(harness): let the local shell be configured instead of following…
feat(harness): let the local shell be configured instead of following…