One of the best things that I did in my longest-running campaign was to have the party sign a Letter of Marque in the first session, the one where their patron was giving them their overarching mission. In real-world history, a Letter of Marque gave the captain of a sailing ship the legal right to raid enemy shipping and not be considered a pirate. For the D&D world, I modified the concept to give a land-based adventuring party the legal right to act like a D&D party (i.e. killing monsters and bad guys and taking their stuff) without being considered bandits.
I came with a printed copy, and had one of the players read it out loud. Then they discussed it, passed it around, and signed it in character. I thought that it would be a random fun thing to do to get in character, and it was, but in hindsight it also did several very useful things for the campaign:
1) It set the tone that I wanted. It said, very clearly, that this was not going to be a murderhobo campaign. Even before they started reading it, having the letter established that international law existed, that people cared about it, and that their behavior would be noticed and have consequences.
2) It established the party as a legal entity, and bound the characters to each other. By giving the characters special rights as long as they remained a unit, it game them a strong in-character reason to resolve conflicts and act as a group. This allowed me to run a sandbox-style game without any manufactured emergencies to keep people together, even though there were some strong and interesting in-character personality differences that might have otherwise pushed the party apart.
3) It did a lot of worldbuilding in a fun and efficient way. Without me reading 'boxed text' or otherwise doing a boring data dump, it established that the game world would have the feel and institutions of the Early Modern Era. It showed that their patron was sophisticated and bureaucratic. And the text of the letter allowed me to throw in a lot of fun details and plot hooks.
Here is the full text of the letter, in approximately the font and format I used. (I had to convert from Word fonts, which have several options that look more old-fashioned and appropriate, to web fonts.) It took two printed pages, with room on the second page for the signatures. Feel free to copy, and adjust for your games.
Letter of Marque and Reprisal
I, Alba Morus
, Duke of Westguard, Paladin of Erathis, Consort of Cerrador, Vice Admiral of the Imperial Elven Navy,
declare to all who shall see this Document that I have Commissioned the undersigned Adventurers to Pursue, Engage, and Dispatch any Enemy of the Holy Corellon Federation, and any entity declared by international law to be ‘Hostis Sapiens Generis’, including but not limited to Monsters, Extraplanar Invaders, Undead, Constructs, Pirates, Slavers, Dangerous Cultists, and Criminals declared Outlaw or assigned a bounty by Due Process of Law, and to Seize their Possessions for whatever purposes the Adventurers see fit;
with the Exception that any Artifacts, Relics, or other items of National Security or Religious Significance to the Holy Corellon Federation or any of its Treaty Allies be returned to Westguard for Just Compensation;
the Proviso that no Intelligent Creature, or organization of such creatures, shall be considered an Enemy of the Federation until after such creature or organization has clearly demonstrated by its actions or words that it is a Threat to Civilization and will, if unchecked, engage in Conquest, Slavery, or Slaughter;
the Instruction that in the case of any Dispute with an Intelligent Creature, or organization of such creatures, all Reasonable Attempts shall be made to Parley with said creature or organization with the goal of securing a Negotiated Peace;
the Strict Command that under no circumstances shall the Adventurers initiate any hostilities against, or take any property from, any Organization or Entity that has signed a peace treaty with Westguard or the Holy Corellon Federation, including but not limited to the Gray Ridge League of Armed Neutrality, all Dwarven Clans operating under The Stonemoot Accords, The Zhonghua Empire, all members of the Grümpf Belt Trading Alliance, Iradin University, the Free Clerics of Kord, the Mica Dome Guardians, Gleamruby's Surface Expedition, the metallic dragons Aurelius Constantine Augustus XIV, Cerrador, Farseeker, and Zqyzxmzk, the Children of the Seventh Star, the Antimony Order, Saverin the Sage, and Egghead the Troll;
the further Command that in the event of a Dispute with such parties, the discovery of a new Dispute between such parties that threatens the Peace of the Region, or the discovery of Intelligence that indicates such parties have taken actions hostile to the Holy Corellon Federation or other Civilized People, the Adventurers shall peacefully Exit the Situation and contact Westguard immediately;
the Proviso that any Crime committed by the members of an Organization, solely against other members of that same Organization, shall be considered an Internal Affair where the Adventurers have no Jurisdiction, except where their assistance is requested by the lawful representatives of the Organization;
and the Understanding that this Document confers no Military or Law Enforcement rights or rank within any territory occupied by any member of the Federation, and in those lands the Adventurers will be considered Ordinary Citizens subject to all rules and laws of the local State, with the exceptions that their income and possessions not be subject to tax and that they be allowed to possess and carry Military-Grade Armaments and ignore all Sumptuary Laws.