Agent terminal command safety #38662
Open
+860
−3
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.
Add Command Safety System for AI Agent Terminal Operations
Summary
Implements a comprehensive command safety system that prevents AI agents from executing dangerous terminal commands without user approval. The system includes built-in dangerous command detection, user-configurable whitelists/blacklists, and cross-platform support for Windows, macOS, and Linux.
Motivation
As mentioned in #37343:
Changes
crates/assistant_tools/src/command_safety.rs
- Core safety logic with dangerous command patternscrates/assistant_tools/src/terminal_tool.rs
- Integration with existing terminal toolcrates/settings/src/settings_content/agent.rs
- New settings schemacrates/agent_settings/src/agent_settings.rs
- Settings integrationKey Features
1. Built-in Dangerous Command Detection
Automatically detects and categorizes dangerous commands:
rm -rf
,del /s /q
,format
,dd
,shred
fdisk
,chmod 777
,reg add
,systemctl disable
curl | sh
,sudo rm
, download-and-execute patternsnc -l
,netsh
modifications2. User-Configurable Options
3. Enhanced UX
rm -rf /
Backward Compatibility
always_allow_tool_actions
settingTesting
Includes comprehensive tests for:
git *
)DISCLAIMER - AI assistance was used (in small amounts) during the creation of this PR. In specific, Copilot was used to generate a structure of the Zed repository and identify potential places where changes were needed (even though it wasn't even right some of the time lol), however, Copilot (nor any other AI model) was used to generate code aside from the odd tab-to-complete here and there. For any further questions regarding this, please let me know.