In the US it’s by state. In New York, opening the box requires a court order no matter what. Getting access to the contents of the box after opening may also require an order from the surrogate court. There’s also a statutory procedure for appointment of an executor that can be complicated by many factors. All of this crap takes time and wastes a lot of money.
Don’t do it. Pay for an attorney to hold it on your behalf if you want a third party to hold on to it.
On top of this, safe deposit boxes are not very safe in general. Banks frequently fubar operations around them and lose, destroy, give access to the wrong people, etc.
Key thing: do not put in a safe deposit box at a bank. Those are sealed once the bank determines that you’re dead.