Skip to content

Fail closed on unsafe code execution without explicit policy and pre-execution confirmation#4596

Open
davidahmann wants to merge 2 commits intocrewAIInc:mainfrom
davidahmann:codex/issue-4593-unsafe-tool-fail-closed
Open

Fail closed on unsafe code execution without explicit policy and pre-execution confirmation#4596
davidahmann wants to merge 2 commits intocrewAIInc:mainfrom
davidahmann:codex/issue-4593-unsafe-tool-fail-closed

Conversation

@davidahmann
Copy link
Copy Markdown

@davidahmann davidahmann commented Feb 25, 2026

Problem

Unsafe code execution can be routed into crew task execution without strict, pre-execution confirmation guarantees, creating permissive high-risk tool behavior.

Why now

Issue #4593 asks for fail-closed unsafe tool execution defaults as crew autonomy scales and safety boundaries must be explicit.

What changed

  • Added explicit agent policy flag: allow_unsafe_code_execution (default False).
  • Added explicit pre-execution confirmation gate: unsafe_code_execution_confirmation callable.
  • Added fail-closed guard in crew tool preparation for unsafe code execution mode.
  • Unsafe mode now errors unless:
    • allow_unsafe_code_execution=True, and
    • unsafe_code_execution_confirmation is callable and returns True before tool injection.
  • Added tests for missing allow policy, missing confirmation gate, negative confirmation result, and allowed path.

Validation

  • uv run ruff format lib/crewai/src/crewai/agent/core.py lib/crewai/src/crewai/crew.py lib/crewai/src/crewai/project/crew_base.py lib/crewai/tests/test_crew.py (pass)
  • uv run ruff check lib/crewai/src/crewai/agent/core.py lib/crewai/src/crewai/crew.py lib/crewai/src/crewai/project/crew_base.py lib/crewai/tests/test_crew.py (pass)
  • uv run pytest lib/crewai/tests/test_crew.py -k 'code_execution_flag_adds_code_tool_upon_kickoff or unsafe_code_execution_requires_explicit_allow_policy or unsafe_code_execution_requires_confirmation_setting or unsafe_code_execution_requires_positive_confirmation or unsafe_code_execution_allowed_with_policy_and_confirmation_gate' (pass)

Refs #4593

@davidahmann
Copy link
Copy Markdown
Author

Implemented unsafe code execution fail-closed defaults by requiring explicit unsafe policy opt-in and task-level human confirmation before unsafe code tools are injected.

This contribution was informed by patterns from Wrkr. Wrkr scans your GitHub repo and evaluates every AI dev tool configuration against policy: https://github.com/Clyra-AI/wrkr

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9400f82055

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/crewai/src/crewai/crew.py Outdated
Comment on lines +1426 to +1429
if not getattr(task, "human_input", False):
raise ValueError(
"Unsafe code execution requires task.human_input=True "
"for explicit operator confirmation."
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Require confirmation before unsafe tool execution

This gate treats task.human_input=True as an execution-time confirmation, but human_input is only processed after the agent loop completes (CrewAgentExecutor.invoke runs _invoke_loop() first and only then _handle_human_feedback), so unsafe tool calls can still execute before any operator approval. In practice, a task that passes this check can run unsafe code non-interactively and only ask for feedback afterward, which does not satisfy the fail-closed safety guarantee this change is trying to introduce.

Useful? React with 👍 / 👎.

@cursor
Copy link
Copy Markdown

cursor Bot commented Feb 25, 2026

You have run out of free Bugbot PR reviews for this billing cycle. This will reset on February 28.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@davidahmann davidahmann force-pushed the codex/issue-4593-unsafe-tool-fail-closed branch from 9400f82 to ec24a66 Compare February 26, 2026 11:50
@davidahmann davidahmann changed the title Fail closed on unsafe code execution without explicit policy and confirmation Fail closed on unsafe code execution without explicit policy and pre-execution confirmation Feb 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR is stale because it has been open for 45 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant