Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(backend/copilot): stop refusing sub-agent briefs and to-dos that mention sudo or subprocess (#15562)

Reinier van der Leer47dc28fa602b
diff --git a/autogpt_platform/backend/backend/copilot/prompting.py b/autogpt_platform/backend/backend/copilot/prompting.py
index 31aa74e2fc..0f6057a498 100644
--- a/autogpt_platform/backend/backend/copilot/prompting.py
+++ b/autogpt_platform/backend/backend/copilot/prompting.py
@@ -474,9 +474,10 @@ never renders picker cards, never charges credits.
# Not shown in local (bubblewrap) mode: --unshare-net blocks all network.
_E2B_TOOL_NOTES = """
### SDK tool-result files in E2B
-When you `Read` an SDK tool-result file, it is automatically copied into the
-sandbox so `bash_exec` can access it for further processing.
-The exact sandbox path is shown in the `[Sandbox copy available at ...]` note.
+When you use `read_tool_result` to read an SDK tool-result file, E2B can copy
+it into the sandbox for further processing with `bash_exec`.
+If the response includes a `[Sandbox copy available at ...]` note, use the
+exact path from that note to access the copy.
### GitHub CLI (`gh`) and git
- To check if the user has their GitHub account already connected, run `gh auth status`. Always check this before running `run_capability(id="tool:connect_integration", input={"provider": "github"})` which will ask the user to connect their GitHub regardless if it's already connected.
diff --git a/autogpt_platform/backend/backend/copilot/prompting_test.py b/autogpt_platform/backend/backend/copilot/prompting_test.py
index 1e5507bdb9..13ed75f641 100644
--- a/autogpt_platform/backend/backend/copilot/prompting_test.py
+++ b/autogpt_platform/backend/backend/copilot/prompting_test.py
@@ -37,11 +37,13 @@ class TestGetSdkSupplementStaticPlaceholder:
@pytest.mark.parametrize("use_e2b", [False, True])
def test_sdk_results_use_the_mcp_read_handler(self, use_e2b):
result = prompting.get_sdk_supplement(use_e2b=use_e2b)
- guidance = result.split("### SDK tool-result files\n", 1)[1].split("\n### ", 1)[
- 0
- ]
- assert "`read_tool_result`" in guidance
- assert "`Read`" not in guidance
+ headings = ["### SDK tool-result files\n"]
+ if use_e2b:
+ headings.append("### SDK tool-result files in E2B\n")
+ for heading in headings:
+ guidance = result.split(heading, 1)[1].split("\n### ", 1)[0]
+ assert "`read_tool_result`" in guidance
+ assert "`Read`" not in guidance
class TestComputerNote:
diff --git a/autogpt_platform/backend/backend/copilot/sdk/security_hooks.py b/autogpt_platform/backend/backend/copilot/sdk/security_hooks.py
index 7574b41fd2..4fd8fe6432 100644
--- a/autogpt_platform/backend/backend/copilot/sdk/security_hooks.py
+++ b/autogpt_platform/backend/backend/copilot/sdk/security_hooks.py
@@ -4,9 +4,7 @@ This module provides security hooks that validate tool calls before execution,
ensuring multi-user isolation and preventing unauthorized operations.
"""
-import json
import logging
-import re
from collections.abc import Callable, Collection, Iterable
from typing import Any, cast
@@ -19,7 +17,6 @@ from backend.copilot.pending_messages import drain_and_format_for_injection
from .governor import TurnGovernor
from .tool_adapter import (
BLOCKED_TOOLS,
- DANGEROUS_PATTERNS,
MCP_TOOL_PREFIX,
WORKSPACE_SCOPED_TOOLS,
stash_pending_tool_output,
@@ -138,20 +135,6 @@ def _validate_tool_access(
if tool_name in WORKSPACE_SCOPED_TOOLS:
return _validate_workspace_path(tool_name, tool_input, sdk_cwd)
- # Check for dangerous patterns in tool input
- # Use json.dumps for predictable format (str() produces Python repr)
- input_str = json.dumps(tool_input) if tool_input else ""
-
- for pattern in DANGEROUS_PATTERNS:
- if re.search(pattern, input_str, re.IGNORECASE):
- logger.warning(
- f"Blocked dangerous pattern in tool input: {pattern} in {tool_name}"
- )
- return _deny(
- "[SECURITY] Input contains a blocked pattern. "
- "This is enforced by the platform and cannot be bypassed."
- )
-
return {}
@@ -304,8 +287,8 @@ def create_security_hooks(
is_copilot_tool = tool_name.startswith(MCP_TOOL_PREFIX)
clean_name = tool_name.removeprefix(MCP_TOOL_PREFIX)
- # Our MCP tools sandbox themselves, so they skip the path and
- # pattern checks — but not the allowed set.
+ # Our MCP tools sandbox themselves, so they skip the path checks —
+ # but not the allowed set.
if not is_copilot_tool:
result = _validate_tool_access(
clean_name, tool_input, sdk_cwd, allowed_tools=allowed
diff --git a/autogpt_platform/backend/backend/copilot/sdk/security_hooks_test.py b/autogpt_platform/backend/backend/copilot/sdk/security_hooks_test.py
index f0641a9213..8e59b9c7d6 100644
--- a/autogpt_platform/backend/backend/copilot/sdk/security_hooks_test.py
+++ b/autogpt_platform/backend/backend/copilot/sdk/security_hooks_test.py
@@ -1,8 +1,8 @@
"""Tests for SDK security hooks — workspace paths, tool access, and deny messages.
These are pure unit tests with no external dependencies (no SDK, no DB, no server).
-They validate that the security hooks correctly block unauthorized paths,
-tool access, and dangerous input patterns.
+They validate that the security hooks correctly block unauthorized paths
+and tool access.
"""
import logging
@@ -223,21 +223,60 @@ def test_bash_builtin_always_blocked():
assert _is_denied(result)
-# -- Dangerous patterns ------------------------------------------------------
+# -- Prose that names a command ----------------------------------------------
-def test_dangerous_pattern_blocked():
- result = _validate_tool_access(
- "SomeTool", {"cmd": "sudo rm -rf /"}, allowed_tools={"SomeTool"}
- )
- assert _is_denied(result)
-
-
-def test_subprocess_pattern_blocked():
- result = _validate_tool_access(
- "SomeTool", {"code": "subprocess.run(...)"}, allowed_tools={"SomeTool"}
[email protected](not _sdk_available(), reason="claude_agent_sdk not installed")
[email protected]("use_e2b", [False, True])
+ "tool_name, tool_input",
+ [
+ (
+ "Agent",
+ {
+ "description": "Audit the deploy script",
+ "prompt": "Check whether deploy.sh calls sudo or subprocess.run",
+ },
+ ),
+ (
+ "Task",
+ {
+ "description": "Find risky calls",
+ "prompt": "List every os.system and rm -rf in the repo",
+ },
+ ),
+ (
+ "TodoWrite",
+ {
+ "todos": [
+ {
+ "content": "Replace the sudo subprocess call",
+ "status": "pending",
+ "activeForm": "Replacing the sudo subprocess call",
+ }
+ ]
+ },
+ ),
+ (
+ "mcp__copilot__bash_exec",
+ {"command": "sudo pip install requests && python -c 'import subprocess'"},
+ ),
+ ],
+)
+async def test_command_text_is_allowed_for_permitted_tools(
+ tool_name, tool_input, use_e2b
+):
+ """Command words are not a substitute for tool authorization."""
+ pre = create_security_hooks(
+ "u1", sdk_cwd=SDK_CWD, allowed_tools=get_copilot_tool_names(use_e2b=use_e2b)
+ )["PreToolUse"][0].hooks[0]
+ result = await pre(
+ {"tool_name": tool_name, "tool_input": tool_input},
+ tool_use_id=None,
+ context={},
)
- assert _is_denied(result)
+ assert not _is_denied(result)
# -- User isolation ----------------------------------------------------------
diff --git a/autogpt_platform/backend/backend/copilot/sdk/tool_adapter.py b/autogpt_platform/backend/backend/copilot/sdk/tool_adapter.py
index 0475c612ac..e018ac3438 100644
--- a/autogpt_platform/backend/backend/copilot/sdk/tool_adapter.py
+++ b/autogpt_platform/backend/backend/copilot/sdk/tool_adapter.py
@@ -1183,23 +1183,6 @@ BLOCKED_TOOLS = {
# Native Read/Write/Edit stay blocked; MCP handlers provide file access.
WORKSPACE_SCOPED_TOOLS = {"Glob", "Grep"}
-# Dangerous patterns in tool inputs
-DANGEROUS_PATTERNS = [
- r"sudo",
- r"rm\s+-rf",
- r"dd\s+if=",
- r"/etc/passwd",
- r"/etc/shadow",
- r"chmod\s+777",
- r"curl\s+.*\|.*sh",
- r"wget\s+.*\|.*sh",
- r"eval\s*\(",
- r"exec\s*\(",
- r"__import__",
- r"os\.system",
- r"subprocess",
-]
-
# Platform-tool names whose MCP wrappers must NOT be exposed to SDK mode.
# Baseline ships an MCP ``TodoWrite`` for model-flexibility parity; SDK mode
# keeps using the CLI-native built-in listed in ``_SDK_BUILTIN_ALWAYS`` so