| name | command-execution-principles |
| description | Apply safe command execution patterns when spawning external processes, shell commands, or system calls from application code. Covers input sanitization, timeout handling, output capture, and error propagation. |
| user-invocable | false |
Command Execution Principles
Security
Never execute user input directly:
- ❌
exec(userInput)
- ❌
shell("rm " + userFile)
- ✅ Use argument lists, not shell string concatenation
- ✅ Validate and sanitize all arguments
Run with minimum permissions:
- Never run commands as root/admin without explicit human approval. If elevated permissions are absolutely required, STOP and request authorization.
- Use least-privilege service accounts
Portability
Use language standard library:
- Avoid shell commands when standard library provides functionality
- Example: Use file I/O APIs instead of
cat, cp, mv
Test on all target OS:
- Windows, Linux, macOS have different commands and behaviors
- Use path joining functions (don't concatenate with /)
Error Handling
Check exit codes:
- Non-zero exit code = failure
- Capture and log stderr
- Set timeouts for long-running commands
- Handle "command not found" gracefully
Command Execution Checklist
Related Principles
- Security Mandate @.claude/rules/security-mandate.md
- Security Principles @.claude/rules/security-principles.md