ShellTool allows agents to execute shell commands in a controlled environment with timeout support and custom execution contexts.
Class Signature
Parameters
Callable[[ShellCommandRequest], str]
default:"None"
Custom command executor function. If not provided, uses the default
_shell_executor that runs commands using subprocess.run.bool
default:"False"
Enable verbose output to print commands before execution and results after completion.
tuple
Additional positional arguments passed to
BaseTool.dict
Additional keyword arguments passed to
BaseTool.Methods
run
Execute a shell command with the specified parameters.ShellCommandRequest
required
A request object containing command execution parameters.
ShellCommandRequest
The request model for shell command execution.str
required
The shell command to execute. Will be properly split using
shlex.split().str
default:"None"
Working directory for command execution. Defaults to current working directory.
dict
default:"None"
Additional environment variables to set. Merged with existing environment.
int
default:"None"
Execution timeout in milliseconds. No timeout if not specified.
Usage Example
With Agentor Agent
Custom Executor
You can provide a custom executor function for specialized command handling:Error Handling
The tool handles various error conditions:- Timeout: Returns “Command execution timed out”
- Command not found: Returns “Error executing command: …”
- Permission denied: Returns subprocess error message
- Other exceptions: Returns descriptive error message
Security Considerations
- Commands are properly escaped using
shlex.split()to prevent injection - Both stdout and stderr are captured
- Timeout support prevents runaway processes
- Custom executors can implement additional validation
- Consider restricting available commands in production environments
Alias
LocalShellTool is an alias for ShellTool:
src/agentor/tools/shell.py:18