Skip to content

Command line code sanitation#1627

Merged
sonichi merged 21 commits intomicrosoft:mainfrom
AaronWard:aw-sanitation
Feb 18, 2024
Merged

Command line code sanitation#1627
sonichi merged 21 commits intomicrosoft:mainfrom
AaronWard:aw-sanitation

Conversation

@AaronWard
Copy link
Contributor

@AaronWard AaronWard commented Feb 11, 2024

This update is a security enhancement for LocalCommandlineCodeExecutor to mitigate the risk of executing potentially harmful commands that could lead to unintended consequences such as data loss or system compromise. This utility aims to enhance security by preventing commands like rm -rf /, direct writes to /dev/sda, and execution of fork bombs (to name a few). Context of a discussion in PR: #1405 (review).

Updates and Changes

  • Added the CommandSanitizer utility class to code_utils.py, designed to inspect code blocks for patterns associated with dangerous commands before execution.
  • Updated LocalCommandlineCodeExecutor to include the use of CommandSanitizer
  • Added tests for CommandSanitizer to validate the effectiveness of the sanitation process.
  • Renamed test/test_code.py to test/test_code_utils.py

Why are these changes needed?

  • needed as we cant trust that an agent won't generate dangerous commands (which is probably a higher risk when using open source LLMs)
  • if someone was to opt to not user docker, these command could affect the user's machine
  • Relevant to [Roadmap] Code Execution and User-Defined Functions #1421

Related issue number

#1405 (review)

Checks

…ode_executor.py and renamed test for code_utils.py
@codecov-commenter
Copy link

codecov-commenter commented Feb 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5aee911) 39.12% compared to head (ae63f8f) 51.06%.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1627       +/-   ##
===========================================
+ Coverage   39.12%   51.06%   +11.94%     
===========================================
  Files          57       57               
  Lines        6073     6082        +9     
  Branches     1360     1482      +122     
===========================================
+ Hits         2376     3106      +730     
+ Misses       3502     2726      -776     
- Partials      195      250       +55     
Flag Coverage Δ
unittests 50.98% <100.00%> (+11.86%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sonichi sonichi added this pull request to the merge queue Feb 18, 2024
Merged via the queue into microsoft:main with commit e50d5a1 Feb 18, 2024
whiskyboy pushed a commit to whiskyboy/autogen that referenced this pull request Apr 17, 2024
* UPDATE - add commandline sanitation class, update local_commandline_code_executor.py and renamed test for code_utils.py

* FIX - precommit run

* UPDATE - moved sanitation function to LocalCommandlineCodeExecutor, moved testo to test_commandline_code_executor.py

* UPDATE - added docstring notice to sanitize_code

* Update autogen/coding/local_commandline_code_executor.py

Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>

* FIX - regular expression

* FIX - function invocation in tests

* UPDATE - pre-commit run

* FIX - pre-commit run -_-

---------

Co-authored-by: Ward <award40@LAMU0CLP74YXVX6.uhc.com>
Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-execution execute generated code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants