You've already forked adk-python
mirror of
https://github.com/encounter/adk-python.git
synced 2026-03-30 10:57:20 -07:00
fix: Fix unsafe_local_code_executor for import scope
Merge https://github.com/google/adk-python/pull/869 How to reproduce the error: ``` from google.adk.code_executors import UnsafeLocalCodeExecutor from google.adk.code_executors.code_execution_utils import CodeExecutionInput result = UnsafeLocalCodeExecutor().execute_code( invocation_context=None, code_execution_input=CodeExecutionInput( code=''' import math def pi(): return math.pi print(pi()) ''' ) ) print(result) ``` output: ``` CodeExecutionResult(stdout='', stderr="name 'math' is not defined", output_files=[]) ``` COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/869 from qieqieplus:main 63f557bbd3b7aa5c2801f5cc9e022d3364177308 PiperOrigin-RevId: 787145189
This commit is contained in:
committed by
Copybara-Service
parent
a858d79b3a
commit
1778490e64
@@ -66,10 +66,9 @@ class UnsafeLocalCodeExecutor(BaseCodeExecutor):
|
||||
try:
|
||||
globals_ = {}
|
||||
_prepare_globals(code_execution_input.code, globals_)
|
||||
locals_ = {}
|
||||
stdout = io.StringIO()
|
||||
with redirect_stdout(stdout):
|
||||
exec(code_execution_input.code, globals_, locals_)
|
||||
exec(code_execution_input.code, globals_)
|
||||
output = stdout.getvalue()
|
||||
except Exception as e:
|
||||
error = str(e)
|
||||
|
||||
Reference in New Issue
Block a user