Examples of implementation (it's like a net to close off the front plane door area) https://www.alpa.org/advocacy/flight-deck-barriers
I've actually seen some airlines position a beverage cart across the entrance of the aisle on the first row to block everyone, while pilots are opening the cockpit door to use the lavatory in flight. There also was a flight attendant behind the cart to tell anyone to back off/turn around.