There are contingency measures for PF incapacitation when PNF is absent from the cockpit.
This includes measures for cockpit decompression (e.g. window breaking)
These measures are balanced with measures to prevent unauthorised passengers forcing entry to the cockpit, including by using force on cabin crew (or PNF) to make them open the cockpit door. Some of these measures are at the airline's discretion.
Cockpit door locks
According to The Guardian Newspaper
A locked door is opened by a flight crew inside the cockpit but can also be unlocked by cabin crew entering a keycode from the outside. Crew inside the cockpit can manually override it to keep a door locked for up to five minutes.
“In the case of an electrical supply failure the door is automatically unlocked, but remains closed,” reads the manual.
It is equipped with a manual escape hatch but that is only accessible from the inside.
According to The LA Times newspaper
safety protocols mandated by Congress in the U.S. after the Sept. 11 attacks ... eliminate the use of keys for entering the cockpit - assuring that no errant passenger can wrestle a key away from a crew member. ...
If a member of the flight crew doesn't open the locked cockpit door from the inside, according to a manual for the Airbus A320 available online, the door can also be unlocked by the cabin crew outside the cockpit by entering a two- to seven-digit code, pre-programmed by the airline, on a keypad.
Protocols and standard procedures around what happens when a pilot leaves the cockpit mid-flight vary according to country and airline.
A flight attendant taking the seat of an absent pilot to ensure there are always two people in the cockpit, and/or blocking access to the open door with a trolley, are often seen on US flights, but not necessarily on others, [Aviation expert Neil Handsford] said. For instance it is not a requirement on Australian flights.
American experts say the typical procedure is for a flight attendant to use a food cart to block access to the cockpit when the pilot opens the door to leave. A flight attendant is supposed to remain in the cockpit and open the door for the pilot upon his or her return. ...
The Airbus manual referred to above says
The Cockpit Door Locking System (CDLS) provides a means of electrically
locking and unlocking the cockpit door. This system is mainly
composed of :
- A keypad, located in the forward cabin, near the cockpit door,
- A toggle switch, located in the center pedestal’s Cockpit Door panel,
- A control unit and its CKPT DOOR CONT normal panel, located on
the overhead panel,
- A buzzer.
The keypad enables
the cabin crew to request access to the cockpit. There are two
different access request types : “Routine” and “Emergency” access
request (Refer to PRO-SUP-25 Cockpit Door Operation - General).
toggle switch enables the flight crew to lock or unlock the cockpit
door, following an access request, thereby allowing or denying the
entry to the cockpit.
The cockpit door control unit is the system controller, in charge of :
- Locking or unlocking the door latches, upon flight crew action.
- Unlocking the door, in case of cockpit decompression
(the door then opens towards the cockpit under differential pressure).
- Indicating system failures of electrical latches and pressure sensors.
- Activating the access request buzzer and turning on the keypad LEDs.
The buzzer sounds in the cockpit for 1 to 9 s to indicate that
a routine access request has been made, or sounds continuously if an
emergency access procedure has been initiated.
The keypad is used to sound the buzzer in the cockpit for 1 to 9 s (3 s by default), by entering a zero to seven-digit code, as programmed by the airline, followed by the '#' key. It is also used to enter the two to seven-digit emergency code, followed by the '#' key, when the flight crew does not respond.
There is also an Airbus Video that shows how the cockpit door lock operates normally and in the case of pilot incapacitation
PF = Pilot flying, PNF = Pilot not flying.