This study aimed to investigate the association between sleep spindle metrics and executive function in individuals with obstructive sleep apnea (OSA). Furthermore, we examined the association of age and education on executive function. A total of 230 (40.90 ± 8.83 years, F/M = 45/185) participants were enrolled. Overnight electroencephalogram (C3-M2) recording detected sleep spindles by a novel U-Net-type neural network that integrates temporal information with time-frequency images. Sleep spindle metrics, including frequency (Hz), overall density (events/min), fast density (events/min), slow density (events/min), duration (sec) and amplitude (µV), were measured. Executive function was assessed using standardized neuropsychological tests. Associations between sleep spindle metrics, executive function, and demographic factors were analyzed using multivariate linear regression. In fully adjusted linear regression models, higher overall sleep spindle density (TMT-A, B=-1.279, p=0.009; TMT-B, B=-1.813, p=0.008), fast sleep spindle density (TMT-A, B=-1.542, p=0.048; TMT-B, B=-2.187, p=0.036) and slow sleep spindle density (TMT-A, B=-1.731, p=0.037; TMT-B, B=-2.449, p=0.034) were associated with better executive function. And the sleep spindle duration both during N2 sleep time (TMT-A, B=-13.932, p=0.027; TMT-B, B=-19.001, p=0.034) and N3 sleep time (TMT-B, B=-29.916, p=0.009; Stroop-incongruous, B=-21.303, p=0.035) was independently associated with better executive function in this population. Additionally, age and education were found to be highly associated with executive function. Specific sleep spindle metrics, higher overall density, fast density and slow density during N2 sleep time, and longer duration during N2 and N3 sleep time, are independent and sensitive indicators of better executive function in young adult and middle-aged patients with OSA. Further research is needed to explore the underlying mechanisms and clinical implications of these findings.