Extraterritoriality is a legal exemption from local legal jurisdiction extended as a courtesy in certain cases, usually by diplomatic agreement. A person or site subject to extraterritoriality is not required to abide by local laws and cannot be prosecuted for violation of those laws. This practice has existed in a variety of forms since at least the 14th century, when formal arrangements were made in several regions of Europe to allow certain nations to enjoy extraterritorial rights.
One of the simplest and best-known examples is the right extended to ambassadors and personnel at an embassy. An embassy, while located in a foreign country, is granted extraterritoriality. This is intended to secure the safety of personnel at the embassy, allowing it to operate as a satellite of the home nation, providing services to citizens while abroad and also assisting non-citizens with immigration matters. Extraterritoriality is also granted to the Holy See and foreign heads of state while traveling.
Nations with strong diplomatic ties may have broader agreements when it comes to extraterritoriality. Some allow military forces belonging to allies to pass through their borders without subjecting them to their own jurisdiction. This allows for easier troop movement, as well as coordination of forces on joint military operations. Broader rights may also be extended to visiting embassy personnel and other members of the foreign service by agreement. Negotiations are carefully conducted as nations determine what kinds of rights they want to extend to foreign actors between their borders.
While people are exempt from the local jurisdiction, they are still subject to other laws. People who commit crimes while enjoying the right of extraterritoriality may be tried in their home nations, and international law can also play a role in handling legal situations that arise with people who are exempt from local and regional laws. This is designed to prevent situations where people commit crimes without punishment, and nations tend to discipline their citizens severely when they violate the law while enjoying immunity, to send a clear message that they do not abuse the right to immunity.
Traveling citizens are subject to local law and can be imprisoned and otherwise penalized for breaking the law. Citizens who do fall afoul of the law are strongly encouraged to make contact with their embassies to receive legal advice and assistance. While the embassy cannot prevent them from facing charges, it can provide attorney recommendations and other services to help citizens when they experience legal problems while traveling.