How Is the Cockpit Door Opened If it’s Locked from Within?
One issue that vexes many people is whether the cockpit door is ever shut. Many people are concerned about whether the cockpit can be accessed from the outside in case of an emergency. Yes, there is a unique code that must be input before takeoff.

If necessary, a flight attendant will enter the code to access the cockpit. The pilot has yet another choice to make. If the pilot sees someone other than an attendant at the door on camera, he has the option of not opening it.