[security] fix(tools): harden Python tool sandbox#94
Merged
mbakgun merged 1 commit intoMay 10, 2026
Conversation
Contributor
|
Thanks ! 🙏 |
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
This PR hardens custom Python tool execution for AI Agent workflows. The previous runner relied on a blacklist of dangerous builtins and modules, but tool code could still use Python object-graph introspection to recover the real
__import__, import blocked modules such asos, and execute host commands or read inherited backend environment variables.The patch adds a pre-execution safety validation step for restricted introspection primitives, removes high-risk builtins that expose the Python object graph, and launches the tool subprocess with a scrubbed environment and isolated temporary working directory.
Security issues covered
Before this PR
exec(code, namespace)in a child Python process.open,eval,exec,getattr, and__import__.().__class__.__base__.__subclasses__()andwarnings.catch_warnings.After this PR
catch_warnings, frame/global escape handles, or private attribute access.objectandtypeare no longer available to tool code as safe builtins.Why this matters
Heym exposes custom Python tools as part of AI Agent workflow execution. A user who can create or edit a workflow can provide Python tool code. Because the runner attempted to sandbox that code, blocked modules such as
osandsubprocessshould not be reachable from the tool body.The object-graph bypass crossed that boundary. In a hosted or multi-user deployment, a malicious workflow tool could execute commands as the backend service user, read inherited secrets such as database or encryption settings, and use those secrets to affect other tenants or backend resources.
Attack flow
warnings.catch_warnings.__import__.os.Affected code
backend/app/services/python_tool_executor.py_RUNNER_SCRIPTexecuted user-provided tool code withexec(code, namespace).execute_tool()launched the runner without an explicit environment or isolated working directory.Root cause
CVSS assessment
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:HSafe reproduction steps
Run this against the vulnerable code from the backend package context:
Expected vulnerable behavior
On vulnerable code, the tool returns the inherited secret and command output, for example:
With this PR, the same payload is rejected before execution with:
Changes in this PR
objectandtypefrom the safe builtin set.Files changed
backend/app/services/python_tool_executor.pybackend/tests/test_python_tool_executor.pyMaintainer impact
Fix rationale
The immediate exploitable path was Python runtime introspection plus ambient process inheritance. Blocking private/dunder introspection removes the demonstrated escape primitive, while launching the child runner with a minimal environment reduces blast radius if another escape is found later.
Type of change
Test plan
Executed locally:
cd /tmp/heym-audit/backend uv run pytest tests/test_python_tool_executor.py -qResult:
cd /tmp/heym-audit/backend ENCRYPTION_KEY=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef \ uv run pytest tests/test_workflow_execution_api.py tests/test_workflow_executor_branching.py tests/test_python_tool_executor.py -qResult:
cd /tmp/heym-audit ENCRYPTION_KEY=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef ./run_tests.shResult:
Result:
./check.shcould not complete locally because the environment does not havebuninstalled:Disclosure notes
This PR is bounded to the Python tool runner sandbox escape and inherited-process-state exposure. It does not address unrelated workflow authorization or file-upload findings, which are covered separately.