async def _execute_python_with_process_timeout(
        self, code: str, timeout: int = 10, *args, **kwargs
    ) -> dict[str, Any]:
        """
        Executes Python code in a separate subprocess with a timeout.
        This provides isolation and prevents re-importing the current agent module.

        Parameters:
          code (str): Python code to execute.
          timeout (int): Timeout in seconds (default: 10).

        Returns:
          dict[str, Any]: Dictionary containing stdout, stderr, return code, etc.
        """
        # Write user code to a temporary file
        with tempfile.NamedTemporaryFile(
            mode="w", suffix=".py", delete=False
        ) as tmp_file:
            tmp_file.write(code)
            script_path = tmp_file.name

        try:
            # Run the script in a fresh subprocess
            result = subprocess.run(
                [sys.executable, script_path],
                capture_output=True,
                text=True,
                timeout=timeout,
            )

            return {
                "result": None,  # We'll parse from stdout if needed
                "stdout": result.stdout,
                "stderr": result.stderr,
                "error": (
                    None
                    if result.returncode == 0
                    else {
                        "type": "SubprocessError",
                        "message": f"Process exited with code {result.returncode}",
                        "traceback": "",
                    }
                ),
                "locals": {},  # No direct local var capture in a separate process
                "success": (result.returncode == 0),
                "timed_out": False,
                "timeout": timeout,
            }
        except subprocess.TimeoutExpired as e:
            return {
                "result": None,
                "stdout": e.output or "",
                "stderr": e.stderr or "",
                "error": {
                    "type": "TimeoutError",
                    "message": f"Execution exceeded {timeout} second limit.",
                    "traceback": "",
                },
                "locals": {},
                "success": False,
                "timed_out": True,
                "timeout": timeout,
            }
        finally:
            # Clean up the temp file
            if os.path.exists(script_path):
                os.remove(script_path)

        Executes Python code in a separate subprocess with a timeout.
        This provides isolation and prevents re-importing the current agent module.

        Parameters:
          code (str): Python code to execute.
          timeout (int): Timeout in seconds (default: 10).

        Returns:
          dict[str, Any]: Dictionary containing stdout, stderr, return code, etc.
        
py/core/agent/research.py