Skip to main content
Component: ShellToolsMixin Module: gaia.agents.tools.shell_tools Import: from gaia.agents.tools.shell_tools import ShellToolsMixin

Overview

ShellToolsMixin provides secure shell command execution with comprehensive rate limiting, command whitelisting, and path validation to prevent abuse while enabling file operations and system queries. Key Features:
  • Whitelist-based command security (only safe, read-only commands)
  • Dual-tier rate limiting (burst + sustained)
  • Path traversal prevention with argument validation
  • Git read-only operations support
  • Output truncation for large results
Security Model:
  • WHITELIST approach (explicitly allow safe commands only)
  • Path validation for all file-like arguments
  • Git subcommand filtering (read-only only)
  • Rate limits prevent DOS attacks

Requirements

Functional Requirements

  1. Safe Command Execution
    • Whitelist: ls, cat, grep, find, git status, etc.
    • Blacklist dangerous commands (rm, chmod, sudo, etc.)
    • Git read-only subcommands only
    • Working directory support
    • Timeout protection (default: 30s)
  2. Rate Limiting
    • Max 10 commands per minute (sustained)
    • Max 3 commands per 10 seconds (burst)
    • Clear wait time messaging
    • Timestamp tracking with deque
  3. Path Security
    • Validate working directory access
    • Check arguments for path traversal (.., separators)
    • Resolve relative paths to absolute
    • PathValidator integration
  4. Output Management
    • Capture stdout and stderr separately
    • Truncate large outputs (max 10,000 chars)
    • Return execution duration
    • Return code reporting

Non-Functional Requirements

  1. Security
    • Zero tolerance for dangerous commands
    • Path validation prevents escape attacks
    • No shell interpolation vulnerabilities
    • Safe parsing with shlex
  2. Performance
    • Configurable timeouts
    • Efficient rate limit checking (O(1))
    • Non-blocking execution
  3. Usability
    • Clear error messages with hints
    • Rate limit guidance (wait times)
    • Allowed command examples on rejection

API Specification

File Location

Public Interface


Implementation Details

Rate Limiting

Command Whitelisting

Git Command Filtering

Path Traversal Prevention


Testing Requirements

File: tests/agents/chat/test_shell_tools_mixin.py

Dependencies


Usage Examples

Example 1: Safe File Operations

Example 2: Git Operations

Example 3: Rate Limiting


ShellToolsMixin Technical Specification