ConnectOnionConnectOnion
DocsUseful Pluginsshell_approval

shell_approval

Require user approval before executing shell commands

What it does

Before executing shell commands, this plugin:

Auto-approves safe commands

Read-only commands like ls, cat, git status execute without prompts.

Asks approval for other commands

Commands that modify files, install packages, or have side effects require user confirmation.

Quick Start

main.py
1from connectonion import Agent 2from connectonion.useful_plugins import shell_approval 3 4def run_command(command: str) -> str: 5 """Execute a shell command.""" 6 import subprocess 7 return subprocess.check_output(command, shell=True).decode() 8 9agent = Agent("devops", tools=[run_command], plugins=[shell_approval]) 10 11agent.input("List files then delete test.txt")
Python REPL
Interactive
[Tool: run_command("ls")] # Auto-approved (safe)
file1.txt test.txt readme.md
 
┌─ Shell Command ────────────────────┐
│ rm test.txt │
└────────────────────────────────────┘
Execute this command?
> Yes, execute
> Auto approve 'rm' in this session
> No, tell agent what I want

Safe Commands (Auto-Approved)

These read-only commands are automatically approved:

File Operations

  • ls, ll
  • cat, head, tail
  • less, more
  • find, fd
  • grep, rg
  • tree, wc

Git (Read-Only)

  • git status
  • git log
  • git diff
  • git show
  • git branch
  • git remote

System Info

  • pwd, whoami
  • env, printenv
  • uname, hostname
  • df, du, free
  • ps, top
  • which, file

Approval Options

When prompted for approval, you can:

1.
Yes, execute

Execute this specific command

2.
Auto approve '{cmd}'

Auto-approve all commands starting with this (e.g., all rm commands for this session)

3.
No, tell agent what I want

Reject and provide feedback to the agent

How it works

main.py
1@before_each_tool 2def _check_approval(agent): 3 pending = agent.current_session.get('pending_tool') 4 if not pending: 5 return 6 7 # Only check bash/shell tools 8 if pending['name'] not in ('bash', 'shell', 'run'): 9 return 10 11 command = pending['arguments'].get('command', '') 12 13 # Skip if safe read-only command 14 if _is_safe(command): 15 return 16 17 # Skip if this command type was auto-approved 18 approved_cmds = agent.current_session.get('shell_approved_cmds', set()) 19 if command.split()[0] in approved_cmds: 20 return 21 22 # Show command and ask for approval 23 choice = pick("Execute this command?", [ 24 "Yes, execute", 25 f"Auto approve '{command.split()[0]}' in this session", 26 "No, tell agent what I want" 27 ]) 28 29 if choice == "No, tell agent what I want": 30 feedback = input("What do you want instead? ") 31 raise ValueError(f"User feedback: {feedback}")

Events Used

EventHandlerPurpose
before_each_tool_check_approvalCheck and prompt before shell commands

Source

connectonion/useful_plugins/shell_approval.py

main.py
1# The plugin is just a list with one event handler 2shell_approval = [before_each_tool(_check_approval)]