Skip to content

[Bug] ShellTools fails to run commands due to incorrect cd usage in argument list #3218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
shlomobamberger opened this issue May 16, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@shlomobamberger
Copy link
Contributor

Description

The ShellTools.run_shell_command method attempts to change the working directory by prepending ["cd",

, ";"] to the command when building the argument list passed to subprocess.run(). This approach is invalid and leads to silent command failures.

Root Cause

  • subprocess.run() does not interpret shell syntax (like cd and ;) when arguments are passed as a list.
  • cd is a shell built-in and does not apply outside the shell context.
  • Without a proper working directory or use of shell=True with a full string, the command does not execute as expected.

Steps to Reproduce

tool = ShellTools("/some/path")
tool.run_shell_command(["grep", "-i", "text", "file.txt"])

Agent Configuration (if applicable)

No response

Expected Behavior

The command should be executed in the desired working directory and return actual results, e.g., running grep on a file in that directory.

Actual Behavior

  • The tool executes subprocess.run() with an invalid command list, resulting in no output or misleading results.
  • No error is thrown, which can lead to silent debugging issues.

Screenshots or Logs (if applicable)

No response

Environment

- OS: MAcOS

Possible Solutions (optional)

#3217

Additional Context

No response

@shlomobamberger shlomobamberger added the bug Something isn't working label May 16, 2025
@willemcdejongh
Copy link
Contributor

Hi @shlomobamberger

I was able to successfully get the correct response from tool.run_shell_command(["grep", "-i", "text", "file.txt"])
using the current implementation.
Would you like to share your exact test snippet and dir tree where your file.txt is located so we can investigate this further?

dirkbrnd pushed a commit that referenced this issue May 20, 2025
#3217)

## Summary

Refactored ShellTools.run_shell_command to correctly handle working
directory changes by using the cwd parameter of subprocess.run() instead
of prepending cd to the shell command. This resolves command execution
failures caused by improper shell syntax in argument lists and improves
robustness and cross-platform compatibility.

issue number: #3218
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants