From 568cc74ae36c8f3e8b4c40eccf8b2d56910541d9 Mon Sep 17 00:00:00 2001 From: liqiang-fit2cloud Date: Wed, 5 Nov 2025 12:37:46 +0800 Subject: [PATCH] fix: remove env from sandbox. --- apps/common/utils/tool_code.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/apps/common/utils/tool_code.py b/apps/common/utils/tool_code.py index 8292ed39d..ef6db5262 100644 --- a/apps/common/utils/tool_code.py +++ b/apps/common/utils/tool_code.py @@ -53,10 +53,6 @@ try: path_to_exclude = ['/opt/py3/lib/python3.11/site-packages', '/opt/maxkb-app/apps'] sys.path = [p for p in sys.path if p not in path_to_exclude] sys.path += {python_paths} - env = dict(os.environ) - for key in list(env.keys()): - if key in os.environ and (key.startswith('MAXKB') or key.startswith('POSTGRES') or key.startswith('PG') or key.startswith('REDIS') or key == 'PATH'): - del os.environ[key] locals_v={'{}'} keywords={keywords} globals_v=globals() @@ -163,10 +159,6 @@ logging.getLogger("mcp.server").setLevel(logging.ERROR) path_to_exclude = ['/opt/py3/lib/python3.11/site-packages', '/opt/maxkb-app/apps'] sys.path = [p for p in sys.path if p not in path_to_exclude] sys.path += {python_paths} -env = dict(os.environ) -for key in list(env.keys()): - if key in os.environ and (key.startswith('MAXKB') or key.startswith('POSTGRES') or key.startswith('PG') or key.startswith('REDIS') or key == 'PATH'): - del os.environ[key] exec({dedent(code)!a}) """ @@ -204,6 +196,7 @@ exec({dedent(code)!a}) file.write(_code) os.system(f"chown {self.user}:root {exec_python_file}") kwargs = {'cwd': BASE_DIR} + kwargs['env'] = {} subprocess_result = subprocess.run( ['su', '-s', python_directory, '-c', "exec(open('" + exec_python_file + "').read())", self.user], text=True,