Skip to content

feat: let a kernel run commands Shell doesn't implement - #190

Merged
ferdingler merged 2 commits into
strands-agents:mainfrom
ferdingler:feat/command-fallback
Nov 2, 2026
Merged

ferdingler merged 2 commits into
strands-agents:mainfrom
ferdingler:feat/command-fallback

Conversation

@ferdingler

@ferdingler ferdingler commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Strands Box needs a way to run commands that Strands Shell doesn't implement. Take git for example: Shell doesn't have it as builtin, but an agent in a box still needs to run it, so Box has to be able to handle it. Today, when Shell doesn't recognize a command, it just fails with "command not found". This PR adds an optional handler on the kernel. When nothing matches, Shell asks the application to run the command instead. The rest of the script keeps working as usual: pipes, &&, $(…). If an app doesn't set a handler, nothing changes for it.

Related Issues

#188.

Documentation PR

None yet. The new trait and context have rustdoc.

Type of Change

New feature

Testing

I tested it through a custom kernel with in-memory fake programs, covering the issue's four examples (the rm one doesn't replay), precedence, each result, redirects, binary pipes, backpressure, early close, the timeout and cancellation. I broke the dispatch, the decline path, the stderr draining, the cancellation, the deadline and the stream close on purpose, and a test caught each one. The existing Rust, Python and Node suites pass unchanged on Linux. I didn't validate a real sandbox or that a real child gets killed on cancel (that's the handler's job), macOS, Windows, or the WASM build, where there's no timer so the deadline is only checked before the handler starts.

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

Add an optional `Kernel::command_fallback()` that returns a
`CommandFallback` handler. The default is `None`, so existing kernels
keep "command not found" and status 127.

When no builtin, function, registered command, multicall name, or
shebang interpreter matches, `run_pipeline` calls the handler with a
`CommandContext`: the final program name, the expanded arguments, the
virtual cwd, the environment with command-local assignments, the
absolute deadline, and the redirected stdin/stdout/stderr as optional
async streams. `Ok(Some(status))` uses the status, `Ok(None)` keeps
today's diagnostic and 127, and `Err` writes the error to the command's
stderr and returns 1. The deadline bounds the handler future.

A kernel with a handler also gets per-stage concurrent stderr draining
and abort-on-drop for foreground pipeline tasks, compound-pipeline
producers, and output drains. Without a handler, draining and task
ownership are unchanged.

Part of strands-agents#188.
@ferdingler
ferdingler marked this pull request as ready for review November 1, 2026 21:28
@ferdingler
ferdingler requested a review from a team as a code owner November 1, 2026 21:28
@ferdingler
ferdingler merged commit da522f9 into strands-agents:main Nov 2, 2026
60 checks passed
@ferdingler
ferdingler deleted the feat/command-fallback branch November 2, 2026 17:45
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