ShellExecutor
autogen.tools.experimental.shell.shell_tool.ShellExecutor #
ShellExecutor(default_timeout=60.0, workspace_dir=None, allowed_paths=None, allowed_commands=None, denied_commands=None, enable_command_filtering=True, dangerous_patterns=None)
Executor for shell commands with timeout and sandboxing support.
Provides multiple layers of security: 1. Command pattern filtering (blocks dangerous commands) 2. Working directory restriction (chroot-like behavior) 3. Allowed/denied command lists (whitelist/blacklist) 4. Path restrictions (limits file system access)
Initialize the shell executor with sandboxing options.
| PARAMETER | DESCRIPTION |
|---|---|
default_timeout | Default timeout in seconds for command execution. TYPE: |
workspace_dir | Working directory for command execution. Commands will be executed within this directory and cannot access files outside of it if path restrictions are enabled. Defaults to current directory. |
allowed_paths | List of allowed path patterns (glob patterns). Commands can only access paths matching these patterns. If None, all paths within workspace_dir are allowed. Use ["**"] to allow all paths. |
allowed_commands | Whitelist of allowed commands (e.g., ["ls", "cat", "grep"]). If provided, only these commands can be executed. None = allow all. |
denied_commands | Blacklist of denied commands (e.g., ["rm", "dd"]). These commands will be blocked. None = use default dangerous patterns. |
enable_command_filtering | Whether to enable pattern-based command filtering. Defaults to True. TYPE: |
dangerous_patterns | Custom dangerous command patterns to check. Each pattern is a tuple of (regex_pattern, error_message). If None, uses DEFAULT_DANGEROUS_PATTERNS. |
Source code in autogen/tools/experimental/shell/shell_tool.py
DEFAULT_DANGEROUS_PATTERNS class-attribute instance-attribute #
DEFAULT_DANGEROUS_PATTERNS = [('\\brm\\s+-rf\\s+/\\s*$', 'Deletion of root filesystem (rm -rf /) is not allowed.'), ('\\brm\\s+-rf\\s+/\\s+', 'Deletion starting from root (rm -rf / ...) is not allowed.'), ('\\brm\\s+-rf\\s+~\\s*$', 'Deletion of entire home directory (rm -rf ~) is not allowed.'), ('\\brm\\s+-rf\\s+~\\s+', 'Deletion starting from home (rm -rf ~ ...) is not allowed.'), ('\\brm\\s+-rf\\s+/(?:etc|usr|bin|sbin|lib|lib64|boot|root|sys|proc|dev)\\b', 'Deletion of critical system directories is not allowed.'), ('>\\s*/dev/sd[a-z][0-9]*\\s*$', 'Direct disk block device overwrite is not allowed.'), ('>\\s*/dev/hd[a-z][0-9]*\\s*$', 'Direct disk block device overwrite is not allowed.'), ('>\\s*/dev/nvme\\d+n\\d+p\\d+\\s*$', 'Direct NVMe disk overwrite is not allowed.'), ('\\bdd\\b.*\\bof=/dev/(?:sd|hd|nvme)', 'Writing to disk devices with dd is not allowed.'), (':\\(\\)\\s*\\{\\s*:\\s*\\|\\s*:\\s*&\\s*\\}\\s*;', 'Fork bombs are not allowed.'), ('\\bmkfs\\.(?:ext[234]|xfs|btrfs|ntfs|vfat|fat)\\s+/dev/', 'Formatting filesystems is not allowed.'), ('\\bformat\\s+[A-Z]:\\s*$', 'Formatting Windows drives is not allowed.'), ('\\bformat\\s+[A-Z]:\\s+/', 'Formatting Windows drives is not allowed.'), ('\\bdel\\s+/[sS]\\s+C:\\\\Windows', 'Deletion of Windows system directory is not allowed.'), ('\\bdel\\s+/[sS]\\s+C:\\\\Program\\s+Files', 'Deletion of Windows Program Files is not allowed.'), ('\\brmdir\\s+/[sS]\\s+C:\\\\Windows', 'Deletion of Windows system directory is not allowed.'), ('\\brm\\s+-rf\\s+/\\*\\s*$', 'Mass deletion of root directory contents is not allowed.'), ('\\brm\\s+-rf\\s+~\\*\\s*$', 'Mass deletion of home directory contents is not allowed.'), ('>\\s*/etc/(?:passwd|shadow|hosts|fstab)', 'Overwriting critical system files is not allowed.'), ('>\\s*/boot/', 'Overwriting boot files is not allowed.')]
dangerous_patterns instance-attribute #
run #
Execute a shell command and return the result.
| PARAMETER | DESCRIPTION |
|---|---|
cmd | Shell command to execute. TYPE: |
timeout | Timeout in seconds. If None, uses default_timeout. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
CmdResult | CmdResult with stdout, stderr, exit_code, and timed_out flag. |
| RAISES | DESCRIPTION |
|---|---|
ValueError | If command violates security restrictions |
Source code in autogen/tools/experimental/shell/shell_tool.py
run_commands #
Execute multiple shell commands concurrently and return results.
| PARAMETER | DESCRIPTION |
|---|---|
commands | List of shell commands to execute. |
timeout_ms | Timeout in milliseconds for each command. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[ShellCommandOutput] | List of ShellCommandOutput objects. |