Skip to content

Studio: ask before running Python fed to Terminal through a heredoc - #17256

Merged
danielhanchen merged 25 commits into
unslothai:mainfrom
NilayYadav:heredoc-interpreter-approval
Nov 10, 2026
Merged

danielhanchen merged 25 commits into
unslothai:mainfrom
NilayYadav:heredoc-interpreter-approval

Conversation

@NilayYadav

@NilayYadav NilayYadav commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Terminal asks before python3 -c "...shutil.rmtree('build')", but the same code as a heredoc (python3 - <<'PY' ... PY) ran with no approval card. Heredoc Python now goes through the same check as python -c, and node/ruby/perl/php heredocs always ask, like node -e. Harmless scripts and cat heredocs are unchanged.

Before / after

Terminal running a python3 - <<'PY' heredoc that calls shutil.rmtree('build'): main runs it with no card, this PR asks.

heredoc-interpreter-approval

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T18:56:08.773624Z faa7373 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Copy link
Copy Markdown

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: 66d1a7b35d

ℹ️ 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 studio/backend/core/inference/tools.py Outdated
Comment on lines +7416 to +7418
for heredoc in _HEREDOC_TO_INTERPRETER_RE.finditer(command):
if not heredoc.group(1).startswith("python") or _depth >= 3:
return True

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restrict heredoc matches to executable shell positions

In auto mode, echo 'node <<EOF' now requires approval even though it only prints its argument (Bash's help echo: “Write arguments to the standard output.”). finditer(command) searches quoted arguments and other heredoc bodies, and the non-Python branch immediately returns True for these non-executable mentions. A quoted cat heredoc containing a Node script example reproduces the same regression, so ordinary documentation/script generation is needlessly interrupted. Restrict this check to executable shell positions and exclude quoted data and other heredoc bodies.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This only adds an approval prompt for a quoted mention, so it fails closed. The herestring check right above it works the same way (echo 'python3 <<<x' already asks), and I'd rather keep the two consistent than add a quote-aware scanner here.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

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

Copy link
Copy Markdown

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: 66d1a7b35d

ℹ️ 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 studio/backend/core/inference/tools.py Outdated
if line == heredoc.group(4):
break
body.append(line)
if _inline_python_is_high_risk("\n".join(body)):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Fail closed if heredoc analysis exceeds the recursion limit

On Python 3.12 with its default recursion limit, a harmless python3 - <<'PY' heredoc assigning a sum of 600 literal 1s (~1.2 KB) now raises RecursionError in _check_signal_escape_patterns's recursive AST visitor. The same command is accepted by the parent classifier and runs successfully, but this new call lets the exception propagate through state/tool_policy.py::_classify, aborting the auto-mode tool turn before an approval card or execution. Catch analyzer recursion failures and fail closed with a high-risk result.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The RecursionError comes from the shared Python analyzer, not the heredoc path: python3 -c with the same 600-term sum and the python tool itself hit it on this head too. Worth fixing in the analyzer in its own PR rather than wrapping just this call.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Nov 10, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Nov 10, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Nov 10, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…, any redirect order) and honour python -i

[skip ci]
danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Nov 10, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…er is named but the heredoc owner or terminator is unresolved

[skip ci]
danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 10, 2026
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.

2 participants