🔒 Security: replace exec() with subprocess sandbox in run_text#2083
Open
shunfeng8421 wants to merge 1 commit into
Open
🔒 Security: replace exec() with subprocess sandbox in run_text#2083shunfeng8421 wants to merge 1 commit into
shunfeng8421 wants to merge 1 commit into
Conversation
run_text() was executing LLM-generated code via exec(code, namespace) in the MetaGPT process with zero isolation. An adversary who controls the code input (via prompt injection or a compromised LLM) gains arbitrary code execution in the host process. Fix: write code to a temporary .py file and execute it in an isolated subprocess via subprocess.run([sys.executable, tmp_path]) with a 30-second timeout. - Removes the in-process exec() vector entirely - Subprocess cannot access MetaGPT's memory, files, or network beyond what the OS permits - Existing run_script() already uses subprocess; run_text() now aligns with the same safety boundary
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.
Summary
Fix arbitrary code execution vulnerability in
RunCode.run_text().Vulnerability
run_text()executes LLM-generated Python code viaexec(code, namespace)directly in the MetaGPT process with zero sandboxing:Impact
An adversary who controls the code input — via prompt injection, a compromised LLM, or a malicious agent — gains arbitrary code execution in the MetaGPT host process, with full access to:
Fix
Write code to a temporary
.pyfile and execute it in an isolated subprocess viasubprocess.run()with a 30-second timeout:Why this is safe
run_script()which already uses subprocess