Definition of Immunity
Immunity is offered to some witnesses and exempts them from legal prosecution. Generally, immunity is offered in exchange for information which may be garnered through self-incriminating testimony. If a criminal is offered prosecutorial immunity they generally cannot prosecuted if they provide testimony in a criminal case. This is most commonly used for witnesses who are minor criminals in a more elaborate conspiracy ring and their testimony may bring down the "ringleaders." Criminals are not granted legal immunity for future crimes after their trial, only past crimes.
Diplomats are also sometimes offered legal immunity called diplomatic immunity and are not brought to trial or charged with crimes related to their job as a diplomat. Exceptions exist if a diplomat commits some types of crimes such as murder. Consider, there are many different types of legal immunity. Talk to a criminal lawyer if you have questions about your right to immunity in a criminal case.