Skip to content

fix: reject an option to sh instead of reading it as a script path - #270

Merged
ferdingler merged 4 commits into
strands-agents:mainfrom
ferdingler:fix/sh-option-not-script
Nov 21, 2026
Merged

ferdingler merged 4 commits into
strands-agents:mainfrom
ferdingler:fix/sh-option-not-script

Conversation

@ferdingler

@ferdingler ferdingler commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Running lash --help or sh -x inside the shell took the option for a script file name, so you got a confusing "no such file" error about a file called --help in the home directory. lash and sh are the shell's own commands, and they only understood -c; anything else in that spot was opened as a script. An agent poking at the shell to see what it does ends up chasing a file that was never there.

Now an option other than -c is reported as an invalid option, the way bash reports one it doesn't know, with status 2. Scripts and -c work as before.

I ran the examples from the issue before and after. Unknown commands with or without arguments, missing paths, directories, and non-executable files all give the same errors as before. I added tests for a long and a short option, and the full Rust suite passes. I didn't run the Python or Node suites since the bindings aren't touched.

I left out a few related things for separate changes: real support for options like -e, -x and -s, reading a script from stdin, and a missing script exiting 126 where bash exits 127.

Related Issues

Part of #207

Documentation PR

N/A

Type of Change

Bug fix

Testing

  • I ran the relevant test suites for the bindings I touched (cargo test --workspace --all-targets, pytest tests/python, npm test)
  • If I touched Rust, I ran cargo fmt and cargo clippy

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ferdingler
ferdingler requested a review from a team as a code owner November 13, 2026 05:09
@ferdingler

Copy link
Copy Markdown
Collaborator Author

@strandly-the-agent Please review this PR

@strandly-the-agent strandly-the-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve once two small things are fixed. The fix is right, and so is its scope: lash --help now fails with a clear status-2 error instead of a "no such file <cwd>/--help" error. Scripts and -c behave the same as before.

  • 🟡 A stray file f (contents x) was committed at the repo root.
  • 🟡 sh -- s, sh -e s, sh -x s, sh -s and sh - all print invalid option, but bash accepts every one of these. Telling a model the flag doesn't exist is the wrong signal. Below is a verified 1-hunk fix: it strips --, as the -c branch already does, and uses the house style <thing> not supported; use <alt>.

Neither is a regression. On main, all of these already failed with a 126 no such file error.

What I verified, passes run, scope, test coverage

✅ Verified at head 36826f5:

  • cargo test --test shell_integration: 1965 passed, 0 failed.
  • Probes through strands-shell -c:
    • sh s a → hi a, sh ./-s b → hi b, lash --help → lash: --help: invalid option with status 2.
    • sh -- s c, sh -x s, sh -e s, sh -s and echo x | sh - all print sh: <opt>: invalid option with status 2.
    • Under bash 5.2, bash -- s c prints hi c, bash -x s traces, and echo … | bash - runs stdin.
    • set -x and set -e work in this shell, so the suggested message points at a real alternative.
  • I applied the inline suggestion locally and rebuilt. sh -- s c → hi c (status 0), sh -x s → the new message (status 2), and sh s a is unchanged.
  • Logs: s3://…/strands-agents/shell/pr/270/{shell_integration-pytest.log,probes.txt}.

Passes:

  • Correctness reviewer (default tier, fresh context): run. Its two findings are the two above, and I re-checked both myself.
  • API bar-raiser: skipped. No Rust or bindings API changed, and the one model-facing string is covered in the inline comment.
  • Adversarial: skipped. The change is a 5-line branch with a single caller (src/exec.rs:3842, only sh/lash). Shebang dispatch (src/exec.rs:3467-3477) passes the resolved path, never a dash option.

Tests: tests/shell_integration.rs:9178-9191 ("lash --help" → "lash: --help: invalid option\n", 2, and "sh -x a" → "sh: -x: invalid option\n", 2) do prove the fix. On main, both inputs reach os.open and fail with strands-shell: …: no such file … and status 126. If you take the suggestion, update the two expected strings and consider adding sh -- FILE.

Scope vs #207: this matches the P2 item "Running a missing binary like lash --help gives no such file or directory: <cwd>/--help", and the tool-level ask to "return a clear error for unsupported … flags". Saying "Part of #207" rather than closing it is right. Deferring real -e/-x/-s and stdin support is reasonable.

Appendix, non-blocking: the sh FILE open-failure exit code (126 vs bash's 127) is already called out in the PR body as follow-up work, so I didn't file it.

Comment thread f Resolved
Comment thread src/exec.rs Resolved
@strandly-the-agent strandly-the-agent mentioned this pull request Nov 13, 2026
8 of 10 tasks
@ferdingler ferdingler mentioned this pull request Nov 13, 2026
10 tasks done
@ferdingler

Copy link
Copy Markdown
Collaborator Author

@strandly-the-agent Please review this PR

@strandly-the-agent strandly-the-agent left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve. Both earlier findings are fixed in ea38228 and 6a5378c. Treating the word after -- as a path even when it starts with a dash (sh -- -s b) is better than what I suggested, and it matches bash. I found nothing new.

What I checked at 6a5378c
  • cargo test --test shell_integration: 1967 passed, 0 failed. That includes the two new -- tests.
  • cargo fmt --check is clean. Clippy shows only warnings that were already there before this PR (e.g. src/exec.rs:3459, src/builtins/find.rs:656); none are in changed lines.
  • Probes through strands-shell -c: sh -- s a → hi a, sh -- -s b → hi b, sh s c → hi c, sh -c 'echo ok' → ok. sh -x s and a bare sh -- both give the new "option not supported" message with status 2. sh -- -c x opens -c as a file, as bash does (bash -- -c x → No such file or directory).
  • A bare sh -- reads stdin in bash. That falls under the stdin support the PR body already defers, so it isn't a finding here.
  • CI is green at 6a5378c. It was still pending when I first posted this review.

Passes: this is a fixes-only follow-up, so I didn't re-run the reviewer subagent. The delta applies my earlier suggestion plus the ---then-path change, which I probed by hand above. I skipped the API pass because no Rust or bindings API changed, and the one model-facing message is the string I proposed. I skipped the adversarial pass because the change is a ~10-line branch with a single caller (src/exec.rs:3842), and I tried its edge cases by hand (--, -- -s, -- -c, bare --).

@ferdingler
ferdingler merged commit ad54fd1 into strands-agents:main Nov 21, 2026
31 checks passed
@ferdingler
ferdingler deleted the fix/sh-option-not-script branch November 21, 2026 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants