Abstract Objective This study aimed to investigate the role of cholesterol metabolism-related genes in nonfunctioning pituitary neuroendocrine tumors (NF-PitNETs) invading the cavernous sinus and analyze the differences in immune cell infiltration between invasive and noninvasive NF-PitNETs. Methods First, a retrospective analysis of single-center clinical data was performed. Second, the immune cell infiltration between invasive and noninvasive NF-PitNETs in the GSE169498 dataset was further analyzed, and statistically different cholesterol metabolism-related gene expression matrices were obtained from the dataset. The hub cholesterol metabolism-related genes in NF-PitNETs were screened by constructing machine learning models. In accordance with the hub gene, 73 cases of NF-PitNETs were clustered into two subtypes, and the functional differences and immune cell infiltration between the two subtypes were further analyzed. Results The clinical data of 146 NF-PitNETs were evaluated, and the results showed that the cholesterol (P = 0.034) between invasive and noninvasive NF-PitNETs significantly differed. After binary logistic analysis, cholesterol was found to be an independent risk factor for cavernous sinus invasion (CSI) in NF-PitNETs. Bioinformatics analysis found three immune cells between invasive and noninvasive NF-PitNETs were statistically significant in the GSE169498 dataset, and 34 cholesterol metabolism-related genes with differences between the two groups were obtained 12 hub genes were selected by crossing the two machine learning algorithm results. Subsequently, cholesterol metabolism-related subgroups, A and B, were obtained by unsupervised hierarchical clustering analysis. The results showed that 12 immune cells infiltrated differentially between the two subgroups. The chi-square test revealed that the two subgroups had statistically significance in the invasive and noninvasive samples (P = 0.001). KEGG enrichment analysis showed that the differentially expressed genes were mainly enriched in the neural ligand–receptor pathway. GSVA analysis showed that the mTORC signaling pathway was upregulated and played an important role in the two-cluster comparison. Conclusion By clinical data and bioinformatics analysis, cholesterol metabolism-related genes may promote the infiltration abundance of immune cells in NF-PitNETs and the invasion of cavernous sinuses by NF-PitNETs through the mTOR signaling pathway. This study provides a new perspective to explore the pathogenesis of cavernous sinus invasion by NF-PitNETs and determine potential therapeutic targets for this disease.