Skip to content

Commit 1778490

Browse files
qieqiepluscopybara-github
authored andcommitted
fix: Fix unsafe_local_code_executor for import scope
Merge #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=#869 from qieqieplus:main 63f557b PiperOrigin-RevId: 787145189
1 parent a858d79 commit 1778490

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/google/adk/code_executors/unsafe_local_code_executor.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ def execute_code(
6666
try:
6767
globals_ = {}
6868
_prepare_globals(code_execution_input.code, globals_)
69-
locals_ = {}
7069
stdout = io.StringIO()
7170
with redirect_stdout(stdout):
72-
exec(code_execution_input.code, globals_, locals_)
71+
exec(code_execution_input.code, globals_)
7372
output = stdout.getvalue()
7473
except Exception as e:
7574
error = str(e)

0 commit comments

Comments
 (0)