Legal immunity

Legal immunity, or immunity from prosecution, is a legal status wherein an individual or entity cannot be held liable for a violation of the law, in order to facilitate societal aims that outweigh the value of imposing liability in such cases. Such legal immunity may be from criminal prosecution, or from civil liability (being subject of lawsuit), or both. The most notable forms of legal immunity are diplomatic immunity, judicial immunity, and witness immunity. One author has described legal immunity as "the obverse of a legal power":
Criticism.
Legal immunities may be subject to criticism because they institute a separate standard of conduct for those who receive them. For example, as one author notes:
Types.
Immunity of government officials.
Many forms of immunity are granted to government officials to enable them to carry out their functions without fear of being sued or charged with a crime for so doing: 
Grants of immunity are particularly important in intergovernmental relations, where traditions have arisen to prevent the diplomatic representatives of a country from being harassed by their host countries.
Such immunities may be granted by law (statutory or constitutional) or by treaty.
Immunity of individuals participating in the legal process.
Such immunities may be granted by law or, for witness immunity, by prosecutors or other authorities on a case-by-case basis, commonly as an agreement with the witnesses.