Safety Levels
Magic Shell includes a comprehensive safety analysis system that categorizes commands by risk level and can block dangerous operations.
Severity Levels
Section titled “Severity Levels”Every command is analyzed and assigned a severity level:
Commands worth reviewing but generally safe.
git checkout mainnpm installls -laBehavior: Executed without confirmation in all safety modes.
Medium
Section titled “Medium”Commands requiring elevated privileges or making notable changes.
sudo apt install nginxchmod 755 script.shrm -rf node_modules/Behavior: May require confirmation depending on safety level.
Commands with significant risk of data loss or system changes.
sudo rm -rf /var/log/*kill -9 -1shutdown -h nowBehavior: Requires confirmation in moderate and strict modes.
Critical
Section titled “Critical”Commands that could cause irreversible system damage. These are always blocked.
rm -rf / # Delete entire filesystem:(){ :|:& };: # Fork bombdd if=/dev/zero of=/dev/sda # Overwrite diskchmod -R 777 / # Recursive permission change on rootSafety Modes
Section titled “Safety Modes”Configure your preferred safety level:
Strict
Section titled “Strict”Confirm all potentially risky commands (low and above).
msh --safety strictBest for:
- Learning environments
- Production servers
- Shared systems
Moderate (Default)
Section titled “Moderate (Default)”Confirm high severity commands; critical commands are always blocked.
msh --safety moderateBest for:
- Daily development work
- Personal machines
- Balanced protection
Relaxed
Section titled “Relaxed”Skip confirmations for most commands; critical commands are still blocked.
msh --safety relaxedBest for:
- Experienced users
- Quick scripting
- Trusted environments
Blocked Patterns
Section titled “Blocked Patterns”Certain dangerous patterns are always blocked, regardless of safety level:
| Pattern | Risk |
|---|---|
rm -rf / | Delete entire filesystem |
rm -rf ~ | Delete home directory |
:(){ :|:& };: | Fork bomb |
> /dev/sda | Overwrite disk |
mkfs.* | Format filesystem |
wget | sh | Pipe download to shell |
curl | bash | Pipe download to shell |
chmod -R 777 / | Recursive root permission change |
How Analysis Works
Section titled “How Analysis Works”Magic Shell analyzes commands using:
- Pattern Matching: Regex patterns detect known dangerous commands
- Privilege Detection: Commands using
sudo,doas, etc. are flagged - Path Analysis: Operations on sensitive paths (
/,/etc,/usr) are scrutinized - Combination Detection: Dangerous flag combinations are identified
Dry-Run Mode
Section titled “Dry-Run Mode”Use dry run to see safety analysis without executing:
msh -n "delete all log files older than 30 days"Output includes:
- The translated command
- Severity level
- Matched patterns (if any)
- Whether confirmation would be required
Customization
Section titled “Customization”Blocked Commands
Section titled “Blocked Commands”Add custom patterns to block in your config:
{ "blockedCommands": [ "DROP TABLE", "TRUNCATE TABLE" ]}Confirmed Patterns
Section titled “Confirmed Patterns”Track patterns you’ve previously confirmed:
{ "confirmedDangerousPatterns": [ "rm -rf node_modules" ]}Best Practices
Section titled “Best Practices”- Start with strict mode when learning or on new systems
- Use dry run (
-n) for unfamiliar queries - Review commands before using
-xflag - Keep moderate mode for daily work
- Never bypass safety for commands you don’t understand