Skip to content

fix: add fallback from rbash to bash/zsh/sh for command execution#2629

Open
majiayu000 wants to merge 2 commits intoantinomyhq:mainfrom
majiayu000:fix/issue-2559-rbash-fallback
Open

fix: add fallback from rbash to bash/zsh/sh for command execution#2629
majiayu000 wants to merge 2 commits intoantinomyhq:mainfrom
majiayu000:fix/issue-2559-rbash-fallback

Conversation

@majiayu000
Copy link

Fixes #2559

Summary

When the user's default shell is rbash (restricted bash), ForgeCode fails because rbash restricts path execution and directory operations.

This PR adds fallback logic so that when rbash is detected, the shell resolution falls back through /bin/bash/bin/zsh/bin/sh.

Changes

  1. crates/forge_infra/src/env.rs: Added resolve_shell() helper that detects rbash and returns the first available fallback shell. Applied in both restricted and non-restricted paths of get_shell_path().

  2. crates/forge_infra/src/executor.rs: Updated prepare_command() to use resolve_shell() so the actual command execution also avoids rbash.

Test Plan

  • cargo check --all-features --workspace passes
  • cargo test --all-features --workspace passes
  • Manual verification: resolve_shell correctly identifies rbash variants (rbash, /bin/rbash, /usr/bin/rbash) and falls back to bash/zsh/sh

When the default shell is set to rbash, shell commands fail because
rbash restricts many operations needed for normal command execution.
This adds a resolve_shell() function that detects rbash and falls back
to /bin/bash, /bin/zsh, or /bin/sh (in that order), applied in both
the environment shell resolution and the command executor.

Closes antinomyhq#2559

Signed-off-by: majiayu000 <1835304752@qq.com>
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions bot added the type: fix Iterations on existing features or infrastructure. label Mar 22, 2026
@majiayu000 majiayu000 marked this pull request as ready for review March 22, 2026 03:48
let is_windows = cfg!(target_os = "windows");
let shell = if self.restricted && !is_windows {
"rbash"
crate::env::resolve_shell("rbash")
Copy link
Contributor

Choose a reason for hiding this comment

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

Inconsistent shell path usage will cause command execution to fail. This line passes "rbash" (bare command name) to resolve_shell(), but if all fallback shells are missing, it returns "rbash" which may not be in PATH. Line 51 in env.rs correctly uses "/bin/rbash" (full path). This inconsistency means:

  1. env.rs restricted mode: tries /bin/rbash → falls back to /bin/bash|/bin/zsh|/bin/sh → worst case returns /bin/rbash
  2. executor.rs restricted mode: tries rbash → falls back to /bin/bash|/bin/zsh|/bin/sh → worst case returns rbash

If fallbacks don't exist, Command::new("rbash") will fail with "command not found" since rbash without a path requires it to be in PATH.

Fix:

crate::env::resolve_shell("/bin/rbash")
Suggested change
crate::env::resolve_shell("rbash")
crate::env::resolve_shell("/bin/rbash")

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Replace resolve_shell() fallback logic with simply using bash
instead of rbash, as suggested in PR antinomyhq#2629 review.

Signed-off-by: majiayu000 <1835304752@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix Iterations on existing features or infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Shell commands fail when default shell is set to rbash

3 participants