Skip to main content
The user requests a system check; the agent runs bounded shell commands and returns stdout safely. Shell tools let AI agents execute commands, manage processes, and monitor system resources.
Prerequisites
  • Python 3.10 or higher
  • PraisonAI Agents package installed
  • Basic understanding of shell commands

Shell Tools

Use Shell Tools to execute shell commands with AI agents.
1

Install Dependencies

First, install the required package:
2

Import Components

Import the necessary components:
3

Create Agent

Create a shell command agent:
4

Define Task

Define the shell task:
5

Run Agent

Initialize and run the agent:

Understanding Shell Tools

What are Shell Tools?

Shell Tools provide command-line capabilities for AI agents:
  • Command execution
  • Process management
  • Output handling
  • Error handling
  • Environment management

Key Components

Shell Agent

Create specialized shell agents:

Shell Task

Define shell tasks:

Process Types

Sequential or parallel processing:

Shell Options

Customize shell operations:

Advanced Shell Management with Multiple Agents

Available Functions

Function Details

execute_command(command, cwd=None, timeout=30, env=None, max_output_size=10000, spill=True, spill_dir=None)

Safely executes shell commands:
  • Timeout protection
  • Output capture
  • Dangerous command blocking (PR #2062) — rm, mkfs, dd, shutdown, etc.
  • Environment and working directory control
  • Large output spill — over-budget output is saved to a retrievable artifact
  • Shell syntax refusal (PR #4968) — redirects, pipes, chains, substitutions and newlines are refused with a named-token error rather than silently mangled
Commands always run with shell=False for security — the string is split with shlex, not handed to a shell. To keep agents from being told an unsupported redirect/pipe/chain succeeded, this tool now refuses those commands with an error naming the token. To combine steps, call execute_command once per step.

Dangerous Command Protection

By default, commands whose base name is in DANGEROUS_COMMANDS are blocked:
The check uses shlex.split + os.path.basename, so rm and /usr/bin/rm are both classified as rm. Unparseable commands fall through to later validation.

Refused Shell Syntax

execute_command refuses shell metacharacters it cannot honour so agents get a clear error instead of a silent no-op. Because commands run with shell=False, a redirect like > is never interpreted — it becomes a literal argument. Before PR #4968, execute_command("echo written > redir.txt") returned success=True with stdout="written > redir.txt\n" and no file, so the agent was told its redirect had succeeded with nothing to correct on. Now the tool refuses the command and names the offending token, so the agent can run the steps separately instead. Tokens refused when they appear outside quotes: The \r carriage return is also treated as a separator. When refused, the result names the token and reports failure:
An agent that tries a redirect is refused, then writes the file with write_file instead:
Quotes decide what counts as syntax. Single-quoted content is left alone (echo '$(whoami)' runs literally), but $(...) and backticks are still refused inside double quotes because POSIX shells evaluate them there.
Users seeing this for the first time need to know what to do instead:

Large Output Handling

When output exceeds max_output_size, the full buffer is saved to a disk artifact and the preview keeps a bounded head/tail plus a pointer to that file.
The agent reads the omitted region straight from the artifact path.
Set spill=False to keep the legacy middle-truncated preview with no persistence. See Tool Output Spill for the full mechanism.

list_processes()

Lists running system processes:
  • Process details
  • Resource usage
  • User information
  • Performance metrics

kill_process(pid: int, force: bool = False)

Terminates system processes:
  • Graceful termination
  • Force kill option
  • Error handling
  • Access control

get_system_info()

Retrieves system information:
  • CPU statistics
  • Memory usage
  • Disk space
  • Platform details
  • Boot time

Example Agent Configuration

Dependencies

The shell tools require the following package:
  • psutil: For system and process information
This will be automatically installed when needed.

Error Handling

All functions include comprehensive error handling:
  • Command execution errors
  • Process access errors
  • Permission errors
  • Timeout errors
  • Resource errors
Errors are handled consistently:
  • Success cases return expected data type
  • Error cases return error details in result
  • All errors are logged for debugging

Common Use Cases

  1. System Monitoring:
  1. Process Management:
  1. Command Execution:
Chaining these with && or piping with | would be refused; run each command as its own execute_command call, as shown.

Best Practices

Configure agents with clear shell focus:
Define specific shell operations:

Common Patterns

Shell Command Pipeline

Custom Tools

Build your own agent tools

Tools Overview

Browse PraisonAI tool documentation

Tool Output Spill

Save large command output to a retrievable artifact

Protected Paths

Guard sensitive files from tool writes