Skip to content

Commit da5c4b0

Browse files
refactor: avoid using temp files in sandbox.
1 parent dec1431 commit da5c4b0

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

apps/common/utils/tool_code.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def exec_code(self, code_str, keywords):
7575
import sys
7676
import json
7777
import base64
78+
import builtins
7879
path_to_exclude = ['/opt/py3/lib/python3.11/site-packages', '/opt/maxkb-app/apps']
7980
sys.path = [p for p in sys.path if p not in path_to_exclude]
8081
sys.path += {python_paths}
@@ -86,11 +87,11 @@ def exec_code(self, code_str, keywords):
8687
for local in locals_v:
8788
globals_v[local] = locals_v[local]
8889
exec_result=f(**keywords)
89-
print("-\n-\n-")
90-
print("{_id}:" + base64.b64encode(json.dumps({success}, default=str).encode()).decode())
90+
builtins.print("-\n-\n-")
91+
builtins.print("{_id}:" + base64.b64encode(json.dumps({success}, default=str).encode()).decode())
9192
except Exception as e:
92-
print("-\n-\n-")
93-
print("{_id}:" + base64.b64encode(json.dumps({err}, default=str).encode()).decode())
93+
builtins.print("-\n-\n-")
94+
builtins.print("{_id}:" + base64.b64encode(json.dumps({err}, default=str).encode()).decode())
9495
"""
9596
if self.sandbox:
9697
subprocess_result = self._exec_sandbox(_exec_code)

0 commit comments

Comments
 (0)