Open-source AI penetration testing tool to find and fix your app’s vulnerabilities.
Python agentsai-hackingai-penetration-testingai-pentestingai-securityartificial-intelligencebug-bountycode-qualityctf-toolscybersecuritycybersecurity-toolsethical-hackinghackingllm-securityoffensive-securitypenetration-testingpentesting-toolsred-teamingsecuritysecurity-automation
fix(python): prevent stdout/stderr race on timeout
0xallam9102b22381ed
diff --git a/strix/tools/python/python_instance.py b/strix/tools/python/python_instance.pyindex 0bf31185..16ff1f7a 100644--- a/strix/tools/python/python_instance.py+++ b/strix/tools/python/python_instance.py@@ -122,6 +122,7 @@ class PythonInstance:result_container: dict[str, Any] = {}stdout_capture = io.StringIO()stderr_capture = io.StringIO()+ cancelled = threading.Event()old_stdout, old_stderr = sys.stdout, sys.stderr@@ -138,14 +139,17 @@ class PythonInstance:except Exception as e: # noqa: BLE001result_container["error"] = efinally:- sys.stdout = old_stdout- sys.stderr = old_stderr+ if not cancelled.is_set():+ sys.stdout = old_stdout+ sys.stderr = old_stderrexec_thread = threading.Thread(target=_run_code, daemon=True)exec_thread.start()exec_thread.join(timeout=timeout)if exec_thread.is_alive():+ cancelled.set()+ sys.stdout, sys.stderr = old_stdout, old_stderrreturn self._handle_execution_error(TimeoutError(f"Code execution timed out after {timeout} seconds"))