Shell Tool
Theshell tool executes shell commands in the workspace directory with comprehensive security controls:
- Command validation against SecurityPolicy
- Environment sanitization to prevent API key leaks
- Working directory control with
cwdparameter - Timeout enforcement (default: 60 seconds)
- Output limits (default: 1 MB)
Parameters
string
required
The shell command to execute
string
Working directory (absolute path within allowed paths; defaults to workspace)
Configuration
Usage
Basic Command
Custom Working Directory
Pipeline Commands
Security Model
SecurityPolicy Validation
When aSecurityPolicy is configured, all commands are validated before execution:
- Low risk — Read-only operations (ls, cat, grep, pwd, echo)
- Medium risk — Write operations (touch, mkdir, git add, git commit)
- High risk — Destructive operations (rm -rf, dd, mkfs, iptables, kill)
*If
require_approval_for_medium_risk = true**If
block_high_risk_commands = true
Example: Approval Required
Example: Blocked Command
Allowed Commands Allowlist
Whenallowed_commands is configured, only listed commands are permitted:
Environment Sanitization
The shell tool clears all environment variables by default, then re-adds only safe functional variables: Safe environment variables:PATH— Command search pathHOME— User home directoryTERM— Terminal typeLANG,LC_ALL,LC_CTYPE— Locale settingsUSER— UsernameSHELL— Default shellTMPDIR— Temporary directory
OPENAI_API_KEYANTHROPIC_API_KEYGEMINI_API_KEY- All other environment variables
Working Directory Control
Default: workspace_dir
By default, commands run inworkspace_dir:
Custom cwd (within workspace)
Custom cwd (outside workspace)
Requiresallowed_paths configuration:
cwd Validation Rules
cwdmust be an absolute pathcwdmust be withinworkspace_dirorallowed_pathscwdis resolved withrealpathAlloc()to prevent symlink escapes- Relative
cwdis rejected: “cwd must be an absolute path”
Platform Shells
The shell tool uses the platform’s default shell:
Commands are passed as a single string to the shell’s
-c flag (Unix) or /c flag (Windows).
Timeout and Output Limits
Timeout
Commands are terminated aftertimeout_ns nanoseconds:
Output Limit
Stdout and stderr are truncated tomax_output_bytes:
Error Handling
Command Failure (Non-Zero Exit Code)
ToolResult.success = false
Signal Termination
Missing Command
No Output
If a command succeeds but produces no output:Use Cases
Git Operations
Build Commands
File Search
Testing
System Info
Source
src/tools/shell.zig:21-117
Testing
Run shell tool tests:- Basic command execution
- Path validation (cwd)
- Policy enforcement
- Timeout handling
- Output limits
- Error cases