Bash Tool¶
Execute shell commands.
Quick Example¶
from mamba_agents.tools import run_bash
# Run a command
result = run_bash("ls -la")
print(result.stdout)
# With timeout
result = run_bash("long_command", timeout=60)
# Check result
if result.return_code == 0:
print("Success!")
else:
print(f"Error: {result.stderr}")
if result.timed_out:
print("Command timed out")
BashResult¶
| Field | Type | Description |
|---|---|---|
stdout |
str | Standard output |
stderr |
str | Standard error |
return_code |
int | Exit code |
timed_out |
bool | Did it timeout? |
API Reference¶
run_bash
¶
run_bash(
command: str,
working_dir: str = ".",
timeout: int = 30,
env: dict[str, str] | None = None,
) -> BashResult
Execute a shell command.
| PARAMETER | DESCRIPTION |
|---|---|
command
|
The shell command to execute.
TYPE:
|
working_dir
|
Working directory for the command.
TYPE:
|
timeout
|
Timeout in seconds (default: 30).
TYPE:
|
env
|
Optional environment variables to add.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BashResult
|
BashResult with stdout, stderr, and return code. |
| RAISES | DESCRIPTION |
|---|---|
TimeoutError
|
If the command times out. |
Source code in src/mamba_agents/tools/bash.py
BashResult
dataclass
¶
Result of a bash command execution.
| ATTRIBUTE | DESCRIPTION |
|---|---|
stdout |
Standard output from the command.
TYPE:
|
stderr |
Standard error from the command.
TYPE:
|
return_code |
Exit code of the command.
TYPE:
|
timed_out |
Whether the command timed out.
TYPE:
|