Since 1994, British legislation gives its secret agents the right to break the law, as long as they have the permission of a “Secretary of State”.
This has enabled the British intelligence services to participate in a wide range of illegal activity, including murder, torture, terrorism, drug trafficking, arms sales and money laundering.

While the first subsection limits the criminal acts to “outside the British Islands”, the 9th subsection shows that also criminal acts “in the British Islands” are allowed...

Section 7 of the Intelligence Services Act 1994 says:
(1) If, apart from this section, a person would be liable in the United Kingdom for any act done outside the British Islands, he shall not be so liable if the act is one which is authorised to be done by virtue of an authorisation given by the secretary of state under this section.
(9)For the purposes of this section the reference in subsection (1) to an act done outside the British Islands includes a reference to any act which—
(a)is done in the British Islands; but
(b)is or is intended to be done in relation to apparatus that is believed to be outside the British Islands, or in relation to anything appearing to originate from such apparatus;

The Dutch legislation seems even more "flexible" in allowing secret agents to commit crimes.

Until 2018, according to art. 21 the intelligence agencies “Wet op de Inlichtingen- en Veiligheidsdiensten”, the AIVD and MIVD can engage in any criminal activity and infiltrate in any criminal organisation (for some reason art. 21 was deleted and than a similar article was made in art. 41)…
The services are authorised to:
a. employ natural persons, whether or not undercover of an assumed identity or capacity, which are the responsibility of an intelligence service:
1 °. to collect information about persons and organisations that may be of importance to an intelligence service;
2 °. to promote or take measures to protect the interests of an intelligence service.
b. establish and deploy legal entities to support operational activities.
The natural person, referred to in the first paragraph, under a, may also be instructed by the intelligence service to carry out actions that result in cooperation with a criminal offense or commit a criminal offense. An instruction as referred to in the first sentence is only given if the proper execution performance of the task of the intelligence service or the safety of the natural person involved so requires.
By or pursuant to a general Order in Council, on the recommendation of the relevant Ministers and Our Minister of Security and Justice jointly, further rules may be laid down with regard to:
a. the conditions under which and the cases in which, in order to execute an instruction by a natural person as referred to in the first paragraph, part a, actions may be carried out which may result in cooperation in the commission of a criminal offense, or commit a criminal offense;
(in Dutch):