Skip to content

feat: set $SHELL to /bin/sh - #283

Open
ferdingler wants to merge 1 commit into
strands-agents:mainfrom
ferdingler:feat/shell-variable
Open

ferdingler wants to merge 1 commit into
strands-agents:mainfrom
ferdingler:feat/shell-variable

Conversation

@ferdingler

Copy link
Copy Markdown
Collaborator

Description

$SHELL wasn't set, so anything that starts "the user's shell" with $SHELL -c ... ended up running an empty command name and failing. Plenty of tools and agent-written scripts do that.

Now the starting environment has SHELL=/bin/sh, the same path command -v sh gives and one that runs this shell inside the sandbox. If the embedder sets SHELL themselves, through the builder or the config file, their value is kept. A custom kernel that builds its own environment isn't affected.

I checked that SHELL=/bin/sh shows up in env, that "$SHELL" -c runs a command, and that a value set through the builder wins over the default. The full Rust check passes.

Related Issues

Part of #207

Documentation PR

None

Type of Change

New feature

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.

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

The initial environment now has SHELL=/bin/sh, which runs this shell
inside the sandbox. A value the embedder sets for SHELL still wins.

Part of strands-agents#207
@ferdingler
ferdingler requested a review from a team as a code owner November 13, 2026 05:16
@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. I found nothing to block on or fix. SHELL=/bin/sh is set in the default env, builder and config-file values still win, and /bin/sh resolves to this shell.

@ferdingler one small optional tweak: builder_env_overrides_shell_var also passes with the vfs_kernel.rs line removed, so it only guards the override order. Keeping it is fine.

✅ What I verified (head 657d4d4)
  • Override order. new_process() sets the defaults first (src/vfs_kernel.rs:292). build() then applies the builder env with proc.set_env (src/shell.rs:1189, :1210-1211). Config [env] goes into the same list and skips keys .env() already set (src/shell.rs:1072-1074). I checked this from the CLI: --config with [env] SHELL="/bin/lash" gives /bin/lash, and "$SHELL" -c 'echo $0' prints lash. The Python and JS bindings both go through builder.env.
  • Resolution. /bin/sh -> lash is created on every build (src/vfs.rs:812). "$SHELL" -c works, including after PATH=/nowhere, and so do exec "$SHELL" -c, "$SHELL" script.sh, subshells and $( ). The MCP session (src/mcp.rs:387) also gets SHELL, because it uses the same new_process().
  • Tests. With the line removed, shell_var_runs_this_shell fails (left: ""), so it really tests the change.
  • Docs and bindings. No README, AGENTS.md, Python or TS test lists the full default env. env_list uses contains, and Python's cfg.env == {} still holds.
  • Runs. cargo test --lib --bins: 72 passed. cargo test --test shell_integration: 1965 passed, 0 failed.
Appendix: non-blocking, older problems this PR makes easier to hit (2)
  • "$SHELL" -lc '…' fails with exit 126 and no such file or directory: /home/lash/-lc. Combined flags aren't parsed, and -lc is a common way tools start "the user's shell". This comes from older sh code, not this PR, and open PR #270 already handles it. Not filed.
  • echo 'echo in' | "$SHELL" prints nothing and exits 0, so a script piped to bare sh is silently ignored. Also from older code. I didn't file it because #224 covered stdin for sh script, and I haven't checked whether bare sh was intentionally left out.

@ferdingler

Copy link
Copy Markdown
Collaborator Author

Thanks. Keeping the override test as is: it's there to guard that an embedder's SHELL wins over the default, and the other test covers the default itself.

This branch has not been deployed

No deployments
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