Say an undercover law enforcement agent has gotten in with an organized crime outfit or a terrorist group. A hypothetical test for the law enforcement operative is to commit a crime alongside the group they have infiltrated.
Are law enforcement personnel within the US, UK, Canada, EU, etc able to commit a crime and have leniancy or immunity if it serves to infiltrate the person into closer trust with a criminal organization so that they can be brought down on a wider scale in the future?
An example of a crime would be participating in a large scale heist or a fraud scheme or even helping with a kidnapping, etc or killing a hostage, etc all for the sake of getting deeper within the organization or entity that is being infiltrated by law enforcement.
Is there any judicial precedent or case law pertaining to this?