If you're an official representative of a sovereign nation such as a member of your country's Embassy staff then you have diplomatic immunity to prosecution in your host nation under the
Vienna Convention. This is to prevent nations from using the law to harrass representatives from countries they might be in dispute with and interfere with their consular or ambassadorial jobs. You can't apply for it as a normal citizen, if you have a job like that then the diplomatic immunity is attached to the role rather than the person.
If you have diplomatic immunity and you break the law in your host nation then you might still be tried and punished in your home nation, the host nation can also ask for your diplomatic immunity to be waived (which
sometimes happens) or you might be expelled from that country.
On two occasions I have been asked, "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.