fix: replace os.system with subprocess.run in unsafe mode pip install#4891
Merged
greysonlalonde merged 3 commits intomainfrom Mar 16, 2026
Merged
fix: replace os.system with subprocess.run in unsafe mode pip install#4891greysonlalonde merged 3 commits intomainfrom
greysonlalonde merged 3 commits intomainfrom
Conversation
Eliminates shell injection risk (A05) where a malicious library name like "pkg; rm -rf /" could execute arbitrary host commands. Using list-form subprocess.run with shell=False ensures the library name is always treated as a single argument with no shell metacharacter expansion. Adds two tests: one verifying list-form invocation, one verifying that shell metacharacters in a library name cannot trigger shell execution. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens CodeInterpreterTool unsafe-mode dependency installation by replacing os.system with subprocess.run list-form invocation to eliminate shell metacharacter expansion, and adds regression tests to prevent reintroduction of shell injection.
Changes:
- Replace
os.system("pip install ...")withsubprocess.run([...])in unsafe mode to avoid shell injection. - Add tests asserting list-form
subprocess.runis used and that shell metacharacters remain a single argument.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
lib/crewai-tools/src/crewai_tools/tools/code_interpreter_tool/code_interpreter_tool.py |
Switches unsafe-mode installs to subprocess.run to prevent shell parsing. |
lib/crewai-tools/tests/tools/test_code_interpreter_tool.py |
Adds tests to verify safe invocation form and non-execution of shell metacharacters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lib/crewai-tools/src/crewai_tools/tools/code_interpreter_tool/code_interpreter_tool.py
Outdated
Show resolved
Hide resolved
S607 flags partial executable paths like ["pip", ...]. Using [sys.executable, "-m", "pip", ...] provides an absolute path and also ensures installation targets the correct Python environment. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
9c0649e to
c1c2572
Compare
greysonlalonde
approved these changes
Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Eliminates shell injection risk (A05) where a malicious library name like "pkg; rm -rf /" could execute arbitrary host commands. Using list-form subprocess.run with shell=False ensures the library name is always treated as a single argument with no shell metacharacter expansion.
Adds two tests: one verifying list-form invocation, one verifying that shell metacharacters in a library name cannot trigger shell execution.
Note
Low Risk
Low risk: limited to how dependencies are installed in
unsafe_mode, plus targeted tests; primary behavior change is reduced command-injection surface area.Overview
Hardens
CodeInterpreterTool.run_code_unsafeby replacingos.system("pip install ...")with list-formsubprocess.run([sys.executable, "-m", "pip", "install", ...]), avoiding shell parsing of user-provided library names.Adds tests asserting
subprocess.runis invoked without a shell and that library strings containing shell metacharacters are passed as a single argument (no command injection).Written by Cursor Bugbot for commit d8b489f. This will update automatically on new commits. Configure here.