Image caption Undercover police work got the Hollywood treatment in Donnie Brasco

For seven years, a police officer posed as an environmental activist and then sparked the collapse of a prosecution case against six other activists when he switched sides and offered to give evidence against the Crown. So what is it like living this kind of double life?

David Corbett has been in the loneliest place in the world - the place inhabited by undercover police officers.

For weeks at a time, he would leave his home, wife and family and turn himself into someone completely different. His own clothes, the pictures in the wallet and the favourite CDs in the family car would be left behind.

He would take to the criminal underworld as someone completely different: new hair, new clothes, jewellery and cars. David Corbett the policeman, the family man, would die - and Mr X, the hardened career drug dealer from Glasgow would be born.

That's the world now under scrutiny after undercover police officer Mark Kennedy spent seven years infiltrating green campaigners only to then offer to give evidence in their defence at trial.

Only Kennedy, known to his protest movement friends as Stone, knows how he got to that place.

But Corbett, who wrote a memoir of his experiences under his assumed name, says that it is all too easy to lose sight of the exit signs when you're deep inside the mind of a fictional person.

He became an undercover officer after a highly fulfilling career investigating organised crime in Scotland. He was picked out for the job and went through three days of special psychological testing in London to see if he was capable of living a lie without losing his mind.

He passed and became one of the northern undercover officers working on organised crime investigations co-ordinated by Scotland Yard.

I disappeared into the shadows, never to be seen again

His first weeks undercover, tasked with bringing down heroin dealers, gave him a high almost as powerful as the hit from the drug itself, he recalls with black humour.

"It was like starting out in the police service again," he says, now in his 50s. "I was cutting my teeth again - I wanted to be exceptional in what I was doing but I had to start small and work my way up."

His first proper undercover job involved buying a "parcel" - street drugs - from a dealer in Newcastle Upon Tyne.

"It was a two-week operation and the target was very suspicious of being caught," he says.

"But it was textbook. I got the parcel, I handed it over to my colleagues from the regional crime squad and then I disappeared into the shadows, never to be seen again. They moved in and made the arrest. The target would never know who I was or my role."

Mission: Keep focused

From there he moved to bigger and more complex operations, eventually creating a believable Scottish crime figure who won the respect and time of major criminals.

But he was only able to do this, he says, because he kept to the rules. Undercover police work, he says, must be tightly focused on gathering specific evidence of a crime. It doesn't work as well as if the officer doesn't know what he is there to do. There has to be a reason for entering the world - and a planned point of exit.

On drugs operations, Corbett would need to gather evidence proving that a major criminal was not only willingly selling drugs - but also willing to secure large quantities of them. He needed specific instructions - but also Home Office-backed guidelines on what he should do in various scenarios.

He had to approach each target with a reasonable suspicion that they were up to no good, rather than go fishing or act as an agent provocateur. He had to become part of the target's world and witness things unfold.

He would never offer to drive a targeted criminal to a meeting with other contacts. But if asked, he would be the driver because refusing to do so would look odd.

You have to maintain that line between the job and the real person

Critically, he says, clear instructions and guidelines provide an officer with security and certainty in a world where they are being asked to behave ambiguously.

At the end of an operation, he would return to his handler, usually a former undercover officer, and run through what he had experienced. He would do the paperwork including detailing any laws he may have broken. And most importantly, he would ditch the physical trappings of being undercover - the haircut, the clothes, and return to his normal world.

"The most important thing that I learned was that first and foremost, whatever I was doing, I had to always remember that I was a police officer," he says.

"Don't allow yourself to get psychologically mixed up in what you are doing and who you are.

"During my time, I came across people who, I have to be honest, I felt sympathetic towards. There was one young kid [who was part of an investigation] who was on drugs and selling heroin. I felt sorry for his life. But you have to remind yourself that it was his decision to put the needle in his arm."

Image caption Sometimes breaking the law maintains cover

The biggest challenge faced by an undercover officer is whether they can break the law. Corbett recalls situations where gang bosses are hosting parties with lines of cocaine ready for guests.

In some cases officers talk their way out of it, claiming a pre-existing medical condition, such as heart palpitations. Others would align themselves with the criminals who stick to the hard drinking. Some officers, fearing for their own lives, take the drug.

"If you have taken the drug, you have got to come out [of the personality] as soon as possible and say on tape [hidden on your body] or to the handler what has happened and why it was a life-threatening situation. You have to maintain that line between the job and the real person."

That line is essential when it comes to enjoying the trappings of criminal wealth. Corbett regularly drove flashy sports cars - his character demanded it.

But if officers start to look on those props as possessions, rather than tools, they can find themselves sucked into their self-created world.

And after five years deep undercover, he knew he had to get out. He went to see the force's doctor for professional psychological help.

"He was not aware that I existed - only three people in the force knew that I existed. That was enough and so I decided I had to stop."

He was diagnosed with post-traumatic stress disorder - but counts himself lucky that he got out in time to rebuild his health.