Shell

Execute shell commands

Overview

Shell tool allows you to execute shell commands from your AI agents. Use with caution!

The user asks to run a command; the agent executes it in the shell and returns the output.

Diagram

ShellTool Flow

👤 User

🤖 Agent

🔧 ShellTool

✅ Result

Installation

bash
pip install "praisonai[tools]"

Quick Start

  1. Simple Usage
    python
    from praisonai_tools import ShellTool
    
    # Initialize
    shell = ShellTool()
    
    # Execute command
    result = shell.execute("ls -la")
    print(result)
  2. With Configuration

    Use the same tool with an agent — see Usage with Agent below, or pass env vars and options from the sections above.

Usage with Agent

python
from praisonaiagents import Agent
from praisonai_tools import ShellTool

agent = Agent(
    name="SysAdmin",
    instructions="You help with system administration tasks.",
    tools=[ShellTool()]
)

response = agent.chat("List all Python processes")
print(response)

Available Methods

execute(command)

Execute a shell command.

python
from praisonai_tools import ShellTool

shell = ShellTool()
result = shell.execute("echo 'Hello World'")

Security Warning

⚠️ Use with caution! Shell commands can be dangerous. Consider:

  • Restricting allowed commands
  • Running in sandboxed environments
  • Validating user input

Common Errors

ErrorCauseSolution
Command not foundInvalid commandCheck command exists
Permission deniedInsufficient permissionsCheck file permissions

How It Works

Diagram
ShellToolAgentUserShellToolAgentUserRequestCall toolQueryDataResultResponse

Best Practices

Allowlist commands

Restrict the agent to a known set of safe commands rather than arbitrary shell access.

Never interpolate untrusted input

Build commands from validated arguments to avoid injection.

Set timeouts

Bound command execution so a hung process doesn’t stall the agent.


Related Tools