Skip to content

Safety Reference

kicode includes a safety system that analyzes shell commands before execution. Dangerous commands require explicit user confirmation.

How Safety Analysis Works

When the AI uses the shell tool, kicode:

  1. Analyzes the command against known dangerous patterns
  2. If a match is found, prompts for confirmation
  3. Only executes after explicit user approval
[tool: shell]
command: "rm -rf build/"
⚠️ This command may be dangerous:
- Pattern matched: rm -rf
Do you want to proceed? [y/N]

Built-in Dangerous Patterns

Destructive File Operations

PatternMatches
rm -rf, rm -fRecursive/forced file deletion
rmdirDirectory removal
unlinkFile unlinking
shredSecure file deletion

Privilege Escalation

PatternMatches
sudoSuperuser commands
suSwitch user
doasOpenBSD privilege escalation
chmod [setuid patterns]Dangerous permission changes
chown, chgrpOwnership changes

Git Destructive Operations

PatternMatches
git push --force, git push -fForce push
git reset --hardHard reset
git clean -f, -d, -xClean working directory
git branch -D, -dDelete branches
git checkout .Discard changes
git restore .Restore all files

System and Disk Operations

PatternMatches
mkfsCreate filesystem
ddDirect disk access
fdisk, partedPartition tools
mount, umountMount operations
systemctl stop/restart/disableService management
service ... stop/restartLegacy service control
launchctl unload/removemacOS service control

Remote Code Execution

PatternMatches
curl ... | sh/bash/pythonPipe to interpreter
wget ... | sh/bash/pythonPipe to interpreter
curl ... > /pathDownload to system path
wget -O /pathDownload to system path
evalEvaluate strings as code
source /dev/stdinSource from stdin

Dangerous Redirects

PatternMatches
> /etc/...Write to system config
> ~/.bashrc, ~/.zshrcModify shell config
> /usr/...Write to system directories
> /bin/, /sbin/Write to binary directories
> /var/...Write to var directories

Process Management

PatternMatches
kill -9Force kill
killallKill by name
pkillPattern-based kill

Network Operations

PatternMatches
iptablesFirewall rules
ufwUncomplicated firewall
firewall-cmdfirewalld management

Package Managers

PatternMatches
apt install, apt-get installDebian packages
yum install, dnf installRed Hat packages
pacman -SArch packages
brew installHomebrew packages
npm install -gGlobal npm packages
pip installPython packages
cargo installRust packages

Container/VM Operations

PatternMatches
docker rm/rmi/stop/killDocker container ops
podman rm/rmi/stop/killPodman container ops
kubectl deleteKubernetes deletions

Scheduled Tasks

PatternMatches
crontabCron job editing
atOne-time scheduled jobs

Remote Operations

PatternMatches
ssh user@hostSSH connections
scpSecure copy
rsync ... :Remote sync

Adding Custom Patterns

Add patterns to your config file:

[safety]
additional_patterns = [
"\\bmy-deploy-script\\b",
"\\brm.*production\\b",
"\\bdrop-database\\b"
]

Pattern Syntax

Patterns use Rust regex syntax:

SyntaxMeaning
\bWord boundary
.*Any characters
\s+One or more whitespace
(a|b)Either a or b
[abc]Any of a, b, c

Example Patterns

[safety]
additional_patterns = [
# Match "deploy" followed by "prod"
"\\bdeploy.*prod",
# Match any rm with force flag
"\\brm\\s+.*-f",
# Match specific script
"\\bmy-dangerous-script\\.sh\\b"
]

Skipping Confirmation

You can configure commands to skip confirmation:

[safety]
skip_confirmation = []

This is intentionally left empty by default. Adding commands here removes a critical safety layer.

Safety Best Practices

  1. Review every confirmation prompt

    • Read the matched pattern
    • Verify the command is intentional
  2. Don’t blindly approve

    • Understand what the command does
    • Check for typos in paths
  3. Use additional_patterns for your workflow

    • Add patterns for project-specific dangerous commands
    • Better safe than sorry
  4. Never skip confirmation in shared environments

    • Each user should make their own safety decisions

How Patterns Are Matched

  1. Command is received from AI
  2. Each pattern is tested against the command
  3. If ANY pattern matches, confirmation is required
  4. User must type ‘y’ or ‘Y’ to proceed
// Simplified matching logic
fn is_dangerous(command: &str) -> bool {
patterns.iter().any(|p| p.is_match(command))
}

Viewing Matched Patterns

When a command is flagged, you’ll see which pattern matched:

⚠️ This command may be dangerous:
- Pattern matched: git push --force
Do you want to proceed? [y/N]