PEP 578 added Python Audit hooks. A rich variety of events (module load, os interactions and so on) triggers audit events which you can subscribe to.
Here's how to do that. First create an embedded python hook:
Embedded Python refers to the integration of the Python programming language into the InterSystems IRIS kernel, allowing developers to operate with data and develop business logic for server-side applications using Python.