Repository navigation
feat: let a kernel run commands Shell doesn't implement - #190
Merged
Merged
Conversation
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
marked this pull request as ready for review
November 1, 2026 21:28
priyasingh2111
approved these changes
Nov 2, 2026
This was referenced Nov 2, 2026
This was referenced Nov 11, 2026
9 of 10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Strands Box needs a way to run commands that Strands Shell doesn't implement. Take
gitfor 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
rmone 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.cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.