Image caption The spy Ecclesiastic used her connections to help the British

Spies, gadgets, disguises, sabotage and murder are all the mainstays of spy fiction. But the truth behind the fiction has now been revealed in a new history of the early years of MI6.

The job of a secret service is to steal other people's secrets and protect its own. But the British Secret Intelligence Service, known as MI6, has come clean about its early years.

It took the unusual step of opening up its secret archive to a historian, Professor Keith Jeffery of Queen's University in Belfast.

After burrowing through the files, he produced an 800 page account which was published on Tuesday.

"[I] was like a child in a sweet shop, a cornucopia. [It was] an extraordinary Aladdin's cave of historical materials," Prof Jeffery told the BBC.

The history recounts how MI6 was founded in 1909 to collect secrets on the build-up of the Germany Navy.

Publishing restrictions

After 1917 it found itself increasingly focusing on the threat from communism, an opponent it watched so closely that it was slow to understand the threat posed by Nazism in Germany in the 1930s.

MI6 also had a bad start to World War II before it began running more successful operations.

Media playback is unsupported on your device Media caption Professor Keith Jeffery: 'It's the holy grail of British archives'

Prof Jeffery was provided access to all surviving files.

However there were limits to what he could publish. In particular he was prevented from revealing the identity of the agents who spied for MI6, often betraying their own country in the process.

"When you hire someone, you say 'Your name is safe with us in perpetuity'," he explained.

Code names are frequently used, but one or two stories were excluded because it would have been too easy to identify the agent. Professor Jeffery said this did not affect the overall narrative.

The history provides insights into the battles for survival that MI6 faced inside government with other departments which were constantly seeking to take control or make the case that a service was not needed.

And there is one section of the book the current chief of MI6, Sir John Sawers, might wish to read carefully.

Image caption Miniature cameras - like this one in a matchbox - were the spies'' stock-in-trade.

His predecessors, especially after World War I, had to fight against swingeing budget cuts from the Treasury.

But it is the story of the individual officers and agents and their operations which are most revealing.

One story revolves around a glamorous 22-year-old woman code named Ecclesiastic.

The mistress of a German intelligence officer based in Lisbon during World War II, she used the relationship to pass on false information which included misleading claims over the damage German bombs were inflicting on London.

Piccadilly Circus and Leicester Square had been totally destroyed, they were told. The intention was to leave the Germans unsure about how successful the targeting of their V rockets was proving, so as to misdirect future attacks.

The agent's case was handled by MI6 officer Klop Ustinov, father of the actor Peter Ustinov.

Mr Ustinov wrote that she clearly enjoyed "the game of mobilizing her ample female resources against normal male instincts".

Some files had been destroyed but Prof Jeffery says he was reassured to find that some had survived which painted MI6 in a less positive light.

Image caption Many secrets were discovered by tapping telephones.

There is a detailed account of the disaster at Venlo in 1939 at the beginning of World War II when German agents lured their British counterparts into a trap at the Dutch border town.

The British agents thought they were there to meet Nazi officers willing to betray Hitler but instead were captured and taken into Germany. There they were forced to expose many of MI6's secrets.

"The damage from the affair was very great," writes Prof Jeffery. "The service's reputation inevitably suffered and the Germans made tremendous propaganda capital out of it."

There is also the story of the aptly titled Operation Embarrass, aimed at blowing up ships in port preparing to take Jewish refugees to Palestine just after World War II.

Britain was still ruling Palestine and politicians ordered MI6 to stop the flow of refugees. A handful of ships were attacked in Italian ports in 1947 and 1948 but the teams were told to make sure there were no personnel on board at the time.

There are also the stories of gadgets and concealment devices, although the technical sophistication was barely a match for those used by James Bond.

Undercover operations

Disguise also plays its part. One rather unfortunate picture reveals exactly what one officer, who was working undercover as a journalist for the Times, looked like, when he was arrested in Madrid wearing women's clothing in 1941.

He claimed "he was taking the feminine garments to a lady in Gibraltar and thought he would try them on for a prank".

Image caption The gadgets used by the spies came in many different forms

And Wilfred "Biffy" Dunderdale, a rather suave character who ran the MI6 station in Paris, is revealed to be one of the inspirations for James Bond.

Mr Dunderdale was a friend of Ian Fleming - the author of the Bond novels.

The issue of a "licence to kill" also arose.

There were debates over whether or not to target individuals for assassination around D-Day. In the end the decision was made not to assassinate, because it might be counterproductive.

However one agent who had been sent into occupied France and turned out to be working for the other side was killed.

The book ends abruptly in 1949 just as the Cold War was taking shape. It was also the moment just before MI6 realised it had a traitor in its midst.

One of its most senior officers, Kim Philby, was busy passing every secret he could lay his hands on to the KGB.

Some secrets, it seems, will have to remain hidden for the moment.