Modern aircraft are equipped with self-pressurized compartments, which allow the aircraft to fly at high altitudes with the same pressure inside and outside the compartments. At the same time, pilots have to wear oxygen masks when flying above 6,000 meters because the outer air becomes thin....
https://www.rollmed.net/face-shield/oxygen-mask-vs-intubation.html