exec tool executes shell commands with built-in safety guards to prevent dangerous operations.
exec
Execute a shell command and return its output.Input Parameters
The shell command to execute. Uses
sh -c on Unix/Linux or powershell on Windows.Optional working directory for the command. Defaults to the tool’s configured working directory.
Response
Returns combined stdout and stderr output.Command output with format:If command fails, includes exit code:
Usage Examples
Basic command:Output Behavior
- Maximum output length: 10,000 characters
- Longer output is truncated with message:
... (truncated, {N} more chars) - Both stdout and stderr are captured and returned
- Empty output returns:
(no output)
Error Conditions
Validation errors:command is required- Missing command parameter
Command blocked by safety guard (dangerous pattern detected)- Dangerous command detectedCommand blocked by safety guard (not in allowlist)- Command not in allowlist (if configured)Command blocked by safety guard (path traversal detected)- Path traversal with workspace restriction enabledCommand blocked by safety guard (path outside working dir)- Absolute path outside workspace
Command timed out after {duration}- Command exceeded timeout (default: 60s)- Command output with exit code for failed commands
Safety Guards
Dangerous Pattern Detection
The following patterns are automatically blocked:| Pattern | Description | Example |
|---|---|---|
rm -rf / rm -fr | Recursive force delete | rm -rf / |
del /f / del /q | Windows force delete | del /f C:\\* |
rmdir /s | Windows recursive delete | rmdir /s C:\\Users |
format / mkfs / diskpart | Disk formatting | format C: |
dd if= | Direct disk write | dd if=/dev/zero of=/dev/sda |
> /dev/sd[a-z] | Write to disk device | echo x > /dev/sda |
shutdown / reboot / poweroff | System power operations | shutdown -h now |
| Fork bomb pattern | Self-replicating process | :(){ :|:& };: |
Workspace Restriction
WhenrestrictToWorkspace=true:
- Commands containing
../path traversal are blocked - Absolute paths in commands are validated to be within workspace
- Prevents reading/writing files outside the working directory
Allowlist Mode
Optionally configure an allowlist of permitted command patterns:Configuration Options
Timeout
Default: 60 secondsPlatform Behavior
Linux/macOS:- Uses
sh -c "{command}" - POSIX-compliant shell execution
- Uses
powershell -NoProfile -NonInteractive -Command "{command}" - PowerShell execution environment
Test Coverage
Fromshell_test.go:
Success cases:
- Basic command execution with output capture
- Custom working directory
- Stderr capture alongside stdout
- Non-existent command/path returns error with exit code
- Timeout terminates long-running commands
- Dangerous commands blocked by safety guards
- Path traversal blocked with workspace restriction
- Long output (>10,000 chars) is truncated
- Empty output returns placeholder message