The vulnerability lies in the RestrictedPythonQuery.check function within aim/storage/query.py. This function uses eval() to execute user-supplied queries in a supposedly restricted environment. However, an unsanitized run_view object is included in the local namespace provided to eval(). This run_view object originates from the QueryRunSequenceCollection.iter_runs method in aim/sdk/sequence_collection.py, which instantiates RunView and passes it to the check method. An attacker can craft a malicious query that leverages the run_view object to traverse its attributes and gain access to powerful Python modules like sys and os. This allows the attacker to escape the sandbox and execute arbitrary commands on the server. The vulnerability is exposed through API endpoints like /api/runs/search/metric/ and /api/runs/search/run where the q parameter accepts these malicious queries. The core issue is the improper sanitization or restriction of objects passed into the eval context, specifically the run_view object, which acts as a bridge to sensitive system functionalities.