Skip to content

fix: send a script's stderr through its redirects - #199

Merged
ferdingler merged 3 commits into
strands-agents:mainfrom
ferdingler:fix/script-stderr
Nov 6, 2026
Merged

ferdingler merged 3 commits into
strands-agents:mainfrom
ferdingler:fix/script-stderr

Conversation

@ferdingler

@ferdingler ferdingler commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Description

A script run with sh file (or lash file, or ./file with a shebang) lost its stderr. Through run, which Python and Node use, the script's stderr just disappeared, and in the CLI it was the other way around: both streams went straight to the terminal, so redirects and even pipes had no effect.

Now the script's output is collected while it runs, the same way a function inside a pipeline already works, and when it finishes it goes wherever that command's redirects point, so 2> err, 2>&1, pipes and $(…) behave like bash in both modes. Two visible changes: in the CLI a script's output shows up when it ends instead of streaming, and with 2>&1 all stdout comes before all stderr; and the output limit message now shows once for each stretch of over-limit writes instead of once per write, because with stderr forwarded that became thousands of lines.

Evidence of how this is fixed in Box

Strands Box carries a vendored copy of Shell and partly fixed this: when a script runs as a pipeline stage, it forwards the script's stdout and stderr after the script ends, which came with another fix (UPSTREAM.md note). That works through run but the CLI is still broken there, and 6 of this PR's 9 tests pass on it.

Related Issues

None.

Documentation PR

None.

Type of Change

Bug fix

Testing

I checked each case against bash, the new tests fail without the fix, and the Rust, Python and Node suites pass. I broke the limit dedupe on purpose and its test caught it. Things I noticed but left alone: a script past a timeout now prints the timeout message twice, in the CLI x=$(sh s.sh) doesn't show the script's stderr (same as any other $(…) in the CLI today), and a script can't read piped stdin. This PR and #196 both add a small helper at the same spot in src/os.rs, so whichever lands second needs a trivial rebase.

  • 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.

A script run with `sh file`, `lash file` or `./file` lost its stderr.
In Shell::run the stderr was dropped, so `sh s.sh 2>e` left e empty
and Output.stderr empty. In the CLI both streams went straight to the
terminal, so `>o`, `2>e` and pipes had no effect.

The script now runs with its output captured, as a function in a
pipeline does, and its stdout and stderr go to the stage's fd 1 and
fd 2 when it ends. So redirects and pipes apply in both modes. The
output is no longer streamed in the CLI.

Captured output over the limit now reports the limit once for each run
of over-limit writes, instead of once for each write.
@ferdingler
ferdingler requested a review from a team as a code owner November 2, 2026 18:46
@ferdingler ferdingler mentioned this pull request Nov 2, 2026
10 tasks done
kevin-orellana
kevin-orellana previously approved these changes Nov 4, 2026
@ferdingler
ferdingler merged commit f64ed13 into strands-agents:main Nov 6, 2026
30 checks passed
@ferdingler
ferdingler deleted the fix/script-stderr branch November 6, 2026 16:54
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