-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[ENHANCEMENT] use a true shell parser to preprocess terminal commands #12040
Description
Problem (one or two sentences)
The shell parser is in charge of identifying command executions (commands, pipeline, shellscripts), evaluate their safety by extracting and comparing individual commands with known, user-defined, allow/deny lists.
It's only one level of sandboxing around the LLM but a very important one since it condition safety and automation.
It's currently regexp-based (split/trim/replace/...)
and consequently doesn't handle advanced shell constructs (some loops and a variety of built-in semantics). ENV=var cmd is just one such example (ENV=var is suggested as the command to allow/deny). A regexp-based validator will never fulfill its mandate (which implies understanding the underlying language at 100%)
.ts shell parsers actually exist:
- https://github.com/webpro-nl/unbash
- https://github.com/tree-sitter/tree-sitter-bash
- We even saw a proprietary/vibe-coded one inadvertently published today
The trade off at stake is code simplicity and readability for enhanced command analysis/review & sandboxing.
But I tend to think such a crucial component deserves it (many people don't use any VM/container/LSM layer that would "contain" what their LLM-enabled code-editor is able to execute).
A shell parser alone won't make the LLM safe to use: many evasions [planned or not] are still possible
But it :
- Drastically reduces the possibility of weaknesses due to parsing errors/inaccuracies.
- Increases the abilities to preemptively analyze complex terminal pipelines
- Bring allow/deny lists at the syntactic level: more detailed (specific arguments combinations), more powerful, more organized and more importantly, make allow/deny list actually 100% reliable.
Context (who is affected and when)
Users of the terminal who allow/deny specific commands issued by the model
Desired behavior (conceptual, not technical)
- Ensure that allowed commands stay allowed within complex shell command-line, independently from specific environment
- Ensuring that denied commands are identified even in complex shell constructs
- Providing more powerful command/argument check-list without relying upon unreliable & inconvenient regexp
- Possible positive outcome regarding environment variable protection/filtering (somehow limiting the impact of an untrusted or malicious LLM or MCP)
Constraints / preferences (optional)
The parser must:
- be fast (parser's latency could be tested against the current, regexp-based, implementation)
- have been previously battle-tested on an existing bash testsuite (including quoting/encoding/...)
- not break on a specific shell (sh/zsh/csh) or at least gently fallback.
- be maintainable (not spreading across Roo codebase, not over engineered, ideally relying upon an existing and reliable implementation)
It should allow user to setup powerful security policy (for efficient & safe command auto-execution) covering:
- commands
- arguments (to some degree)
- environment (could be about using, displaying or setting certain variables) [nice to have]
with user-configured preferences - handle PATH tricks and alias (that would lead to execute a denied command or denying an allowed command)
It could also represent an appreciable fence over sudo usage: If bridged with well-known lists, it could even let users whitelisting specific sudo-enabled commands.
Request checklist
- I've searched existing Issues and Discussions for duplicates
- This describes a specific problem with clear context and impact
Roo Code Task Links (optional)
No response
Acceptance criteria (optional)
No response
Proposed approach (optional)
Use a shell parser
Trade-offs / risks (optional)
- code simplicity and readability vs enhanced command analysis (user preference regarding dangerous/safe commands, overall sandboxing)
- specific shell features (sh vs bash sv zsh)
- environment inheritance (environment variable, aliases handling, custom functions, init/rc files)