@@ -54,8 +54,6 @@ def exec_code(self, code_str, keywords):
5454 path_to_exclude = ['/opt/py3/lib/python3.11/site-packages', '/opt/maxkb-app/apps']
5555 sys.path = [p for p in sys.path if p not in path_to_exclude]
5656 sys.path += { python_paths }
57- os.environ['MAXKB_SANDBOX_PYTHON_BANNED_HOSTS'] = '{ self .banned_hosts } '
58- os.environ['LD_PRELOAD'] = '/opt/maxkb-app/sandbox/sandbox.so'
5957 locals_v={ '{}' }
6058 keywords={ keywords }
6159 globals_v=globals()
@@ -162,8 +160,6 @@ def generate_mcp_server_code(self, code_str, params):
162160path_to_exclude = ['/opt/py3/lib/python3.11/site-packages', '/opt/maxkb-app/apps']
163161sys.path = [p for p in sys.path if p not in path_to_exclude]
164162sys.path += { python_paths }
165- os.environ['MAXKB_SANDBOX_PYTHON_BANNED_HOSTS'] = '{ self .banned_hosts } '
166- os.environ['LD_PRELOAD'] = '/opt/maxkb-app/sandbox/sandbox.so'
167163exec({ dedent (code )!a} )
168164"""
169165
@@ -202,7 +198,10 @@ def _exec_sandbox(self, _code, _id):
202198 file .write (_code )
203199 os .system (f"chown { self .user } :root { exec_python_file } " )
204200 kwargs = {'cwd' : BASE_DIR }
205- kwargs ['env' ] = {}
201+ kwargs ['env' ] = {
202+ 'LD_PRELOAD' : '/opt/maxkb-app/sandbox/sandbox.so' ,
203+ 'MAXKB_SANDBOX_PYTHON_BANNED_HOSTS' : self .banned_hosts ,
204+ }
206205 subprocess_result = subprocess .run (
207206 ['su' , '-s' , python_directory , '-c' , "exec(open('" + exec_python_file + "').read())" , self .user ],
208207 text = True ,
0 commit comments