Skip to main content
Use the run_bash tool so an autonomous agent can run shell commands on the terminal.

When to use it

  • The agent needs to run CLI commands (e.g. ls, python script.py, git status).
  • You use max_loops="auto" and want the agent to have terminal access.
  • You want to keep other tools restricted and only add bash execution.

Enable the tool

Include "run_bash" in selected_tools when creating the agent:

Run a task

The agent will plan and call run_bash when it needs to run a command:

Tool parameters

Commands run in the Python process’s current working directory, not the agent workspace. The tool returns the exit code, stdout and stderr. Long-running commands should use a higher timeout_seconds or be avoided.

Limits and safety checks

  • Length: commands over 512 characters are refused. If the command is a heredoc or redirect, the refusal tells the model to write the file with create_file or update_file instead, so give the agent those tools when it needs to write files.
  • Blocklist: commands matching dangerous patterns are refused, including recursive rm, piping into a shell or interpreter, sudo, shutdown and reboot, printenv, curl -d, redirects into /etc or /usr, and redirects to disk devices or /dev/null.
  • Output cap: the result is capped at a quarter of the agent’s context_length in tokens, with a marker saying how much was cut. Set context_length lower for a tighter cap.
  • Searches: for finding files or matching text, the glob and grep tools are preferred over find and grep through bash.
The blocklist is a guard, not a sandbox. The command runs with your process’s permissions. Run untrusted tasks in a container or a throwaway working directory.

Example file

A starting-point script is in the repo. It builds this agent and prints the available tool names; uncomment the agent.run(...) call to run a task:

See also