ShellTool allows agents to execute shell commands in a controlled environment with timeout support and custom execution contexts.
Class Signature
Parameters
Custom command executor function. If not provided, uses the default
_shell_executor that runs commands using subprocess.run.Enable verbose output to print commands before execution and results after completion.
Additional positional arguments passed to
BaseTool.Additional keyword arguments passed to
BaseTool.Methods
run
Execute a shell command with the specified parameters.A request object containing command execution parameters.
ShellCommandRequest
The request model for shell command execution.The shell command to execute. Will be properly split using
shlex.split().Working directory for command execution. Defaults to current working directory.
Additional environment variables to set. Merged with existing environment.
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:
/home/daytona/workspace/source/src/agentor/tools/shell.py:18