MCPcopy Index your code
hub / github.com/1Panel-dev/MaxKB / _exec

Method _exec

apps/common/utils/tool_code.py:351–379  ·  view source on GitHub ↗
(self, execute_file, _id)

Source from the content-addressed store, hash-verified

349 return app_config
350
351 def _exec(self, execute_file, _id):
352 kwargs = {
353 "cwd": BASE_DIR,
354 "env": {
355 "LD_PRELOAD": f"{_sandbox_path}/lib/sandbox.so",
356 "_ID": _id,
357 },
358 }
359
360 def _set_resource_limit():
361 if not _enable_sandbox or not sys.platform.startswith("linux"):
362 return
363 with suppress(Exception):
364 resource.setrlimit(resource.RLIMIT_AS, (_process_limit_mem_mb * 1024 * 1024,) * 2)
365 with suppress(Exception):
366 os.sched_setaffinity(0, set(random.sample(list(os.sched_getaffinity(0)), _process_limit_cpu_cores)))
367
368 try:
369 subprocess_result = subprocess.run(
370 [sys.executable, execute_file],
371 timeout=_process_limit_timeout_seconds,
372 text=True,
373 capture_output=True,
374 **kwargs,
375 preexec_fn=_set_resource_limit,
376 )
377 return subprocess_result
378 except subprocess.TimeoutExpired:
379 raise Exception(_(f"Process execution timed out after {_process_limit_timeout_seconds} seconds."))
380
381 def validate_mcp_transport(self, code_str):
382 servers = json.loads(code_str)

Callers 1

exec_codeMethod · 0.95

Calls 1

runMethod · 0.45

Tested by

no test coverage detected