Skip to content

Commit d9b7810

Browse files
fix: remove env from sandbox.
1 parent b841d86 commit d9b7810

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

apps/common/utils/tool_code.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ def exec_code(self, code_str, keywords):
5353
path_to_exclude = ['/opt/py3/lib/python3.11/site-packages', '/opt/maxkb-app/apps']
5454
sys.path = [p for p in sys.path if p not in path_to_exclude]
5555
sys.path += {python_paths}
56-
env = dict(os.environ)
57-
for key in list(env.keys()):
58-
if key in os.environ and (key.startswith('MAXKB') or key.startswith('POSTGRES') or key.startswith('PG') or key.startswith('REDIS') or key == 'PATH'):
59-
del os.environ[key]
6056
locals_v={'{}'}
6157
keywords={keywords}
6258
globals_v=globals()
@@ -163,10 +159,6 @@ def generate_mcp_server_code(self, code_str, params):
163159
path_to_exclude = ['/opt/py3/lib/python3.11/site-packages', '/opt/maxkb-app/apps']
164160
sys.path = [p for p in sys.path if p not in path_to_exclude]
165161
sys.path += {python_paths}
166-
env = dict(os.environ)
167-
for key in list(env.keys()):
168-
if key in os.environ and (key.startswith('MAXKB') or key.startswith('POSTGRES') or key.startswith('PG') or key.startswith('REDIS') or key == 'PATH'):
169-
del os.environ[key]
170162
exec({dedent(code)!a})
171163
"""
172164

@@ -204,6 +196,7 @@ def _exec_sandbox(self, _code, _id):
204196
file.write(_code)
205197
os.system(f"chown {self.user}:root {exec_python_file}")
206198
kwargs = {'cwd': BASE_DIR}
199+
kwargs['env'] = {}
207200
subprocess_result = subprocess.run(
208201
['su', '-s', python_directory, '-c', "exec(open('" + exec_python_file + "').read())", self.user],
209202
text=True,

0 commit comments

Comments
 (0)