| 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) |