Overview
The@tinyclaw/shell package provides controlled shell command execution for Tiny Claw AI agents. It combines a permission engine with a shell executor to enforce safe command execution.
Safety Layers
- Permission engine — Allowlist + blocklist + approval store
- Shield integration — Runtime SHIELD.md threat evaluation
- Owner authority — Only the owner can run shell commands
- Executor safety — Timeout, output truncation, env filtering
Permission Model
All commands are DENIED by default unless:- Matched by built-in safe allowlist (read-only commands like
ls,cat,git status) - User-configured allowed commands/patterns
- One-time owner approval (stored for future use)
Installation
Usage
Basic Setup
Running Commands
Permission Management
Cleanup
API Reference
createShellEngine(config?)
Create a shell engine that combines permission checks with execution.
Configuration options.
Working directory for command execution. Defaults to
process.cwd().Default timeout in milliseconds.
Maximum allowed timeout in milliseconds.
Maximum output size in bytes before truncation (10 KB).
Additional allow patterns from user config.
Previously persisted approvals to restore.
Additional environment variables to pass to commands.
ShellEngine
ShellEngine
run(command, timeoutMs?)
Execute a command with full permission checks.
The shell command to execute.
Override timeout in milliseconds (max: 120000).
Formatted result string suitable for the agent.
shutdown()
Shutdown and clean up resources. Clears all session (non-persistent) approvals.
createShellTools(shell)
Create agent tools for shell interaction.
The shell engine instance.
Tool[] - Array containing 3 tools:
run_shell— Execute a shell commandshell_approve— Approve a pending commandshell_allow— Add/remove/list allow patterns
ShellPermissionEngine
Permission evaluation and approval management.
evaluate(command)
Evaluate whether a command is allowed.
The command to evaluate.
Permission decision with reason and matched rule.
approve(command, persistent?)
Record an owner approval for a command.
The exact command to approve.
Whether the approval persists across sessions.
revoke(command)
Revoke a previously granted approval.
The command to revoke.
Whether an approval was removed.
listApprovals()
List all current approvals.
Array of approval records.
addAllowPattern(pattern)
Add a command or glob pattern to the user allowlist.
Glob pattern like
"make *" or exact command.removeAllowPattern(pattern)
Remove a pattern from the user allowlist.
The pattern to remove.
Whether the pattern was found and removed.
ShellResult
Result object from the executor.
Whether the command completed successfully (exit code 0).
Combined stdout output (truncated if necessary).
Combined stderr output (truncated if necessary).
Process exit code.
Execution duration in milliseconds.
Whether the command was killed due to timeout.
Whether stdout was truncated.
Built-in Safe Commands
The following commands are auto-allowed without approval:- Filesystem reading:
ls,cat,head,tail,find,tree,stat - Text processing:
grep,awk,sed,sort,uniq,cut,diff - System info:
echo,pwd,whoami,hostname,uname,date,env - Package managers:
npm ls,yarn info,pip list,cargo tree - Git (read-only):
git status,git log,git diff,git show,git branch - Process info:
ps,top,htop,lsof
Dangerous Patterns (Always Blocked)
These patterns are always blocked regardless of allowlist:- Destructive operations:
rm -rf /,mkfs,dd if=/dev/* - Privilege escalation:
sudo,su,chmod 777 - Code injection:
eval,exec,source,| sh - Network exfiltration:
nc -l,ncat,/dev/tcp/ - System modification:
shutdown,reboot,systemctl - Credential access:
export,.env,ssh,scp
Environment Variable Filtering
Sensitive environment variables are automatically stripped before passing to child processes:- API keys:
OPENAI_API_KEY,ANTHROPIC_API_KEY,GITHUB_TOKEN - Database credentials:
DATABASE_URL,DB_PASSWORD,REDIS_PASSWORD - Generic secrets: Any var containing
_KEY,_SECRET,_TOKEN,_PASSWORD