-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Enhancing the local Python sandbox #1551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
updating the local_python_executor to prevent execution while Python code attempt to access dunder methods. A developer can authorize a dunder method the same way as he authorizes tools, for example: custom_executor = LocalPythonExecutor([]) custom_executor.send_tools({"__getattribute__":"__getattribute__","__subclasses__":"__subclasses__"})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the security fix!
I think there are some cases where this fix is not working: see failing tests.
- For example, what about a subclass calling
super().__init__()
? This PR does not allow it.
@albertvillanova thanks for the response. |
Thanks for the clarification, @nnfrog! Just to clarify, I wasn't referring to
That said, you're absolutely right that More broadly, though, I wonder if we should consider allowing some basic built-in methods by default (such as In any case, I agree this could be discussed and handled separately in a dedicated PR. Would be great to hear your thoughts on that direction. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I forgot to ask: do you have a mechanism in mind for explicitly allowing methods like __init__
, for example? In the current design, tools/functions are passed via static_tools
as a dictionary mapping function names to their corresponding callables; but in the case of __init__
, there's no standalone callable we can provide in the same way.
I think this is something we should address directly in this PR, as it ties into the broader question of how we handle access to special methods. As I mentioned earlier, it's always a delicate balance between maintaining security and enabling useful functionality.
Hi @albertvillanova and sorry for the delay in my response About how to implement it - I think a list with method names as strings, and then checking it against a func.name result could be a valid option WDYT? |
Updating the local_python_executor to prevent execution while Python code attempt to access dunder methods (and not just dunder attributes).
A developer can authorize a dunder method the same way as he authorizes tools, for example: