Overview
Thebash tool allows agents to execute shell commands in a controlled environment. Commands run with a configurable timeout and return stdout, stderr, and exit code information.
Tool Definition
The shell command to execute. Only non-sudo commands are permitted.
Timeout in seconds for command execution. Must be a positive number. Commands that exceed the timeout return exit code -1.
Return Value
The tool returns aShellResult object with:
exitCode: Numeric exit code (0 for success, -1 for timeout, non-zero for errors)stdout: Standard output from the commandstderr: Standard error output from the command
Behavior
Timeout Handling
When a command exceeds the specified timeout:- Exit code is set to -1
- Both stdout and stderr are empty strings
- Context message indicates the timeout duration
Permission Derivation
The tool implements intelligent permission derivation for the “always allow” feature:- Extracts the first word of the command (before the first space)
- Creates a permission pattern like
command **to match the base command with any arguments - Example:
ls -la /tmpderives permission forls **
Output Format
The context returned to the agent includes:- stdout section (if present)
- stderr section (if present)
- exit code line
Usage Examples
Basic Command Execution
Command with Custom Timeout
Handling Errors
Timeout Example
Implementation Details
The tool is defined inpackages/ai/tools/bash.ts and uses the execShell utility from ./lib/shell for actual command execution.
Schema Definition
Execute Function
The execute function:- Calls
execShellwith the command and timeout - Checks for timeout condition (exitCode -1 with no output)
- Formats stdout, stderr, and exit code into context string
- Returns both formatted context and structured result
