Frontiers have a dynamism of their own in Graham Greene’s fiction, and typically set off a reflex of unease. The novelist’s father, Charles Greene, had been the pious Anglican headmaster of a public school in Berkhamsted near London, and each day the schoolboy Greene experienced divided loyalties as he left the family quarters to go to class. Greene’s literary gift, later, was to locate the moment of crisis when a character transgresses a border of some sort, whether geographical, religious or political, and life is exposed in all its drab wonder.

East-West border tensions were rife in the Baltic outpost of Estonia, which Greene visited in spring 1934, “for no reason”, he writes in his 1980 memoir Ways of Escape, “except escape to somewhere new”. His fellow passenger on the flight from Latvia was an ex-Anglican clergyman installed in the Estonian capital of Tallinn as a diplomat. Greene does not name the man but he was Peter Edmund James Leslie, appointed His Majesty’s Vice-Consul in Tallinn in 1931. Leslie was a Catholic convert who worked, rather dubiously, as a munitions salesman. He might have been a spy in an Eric Ambler novel. In fact, Leslie was Greene’s first (and possibly inadvertent) contact with British intelligence. A Foreign Office file notes: “Leslie is one of the best representatives the SIS [the Secret Intelligence Service, or M16] have got in eastern Europe.”

Espionage runs through Greene’s life like a Cold War melodrama. A film sketch conceived by Greene in 1944, “Nobody to Blame”, concerns a British sales representative in Estonia (“Latesthia”) for Singer Sewing Machines, who turns out to be an SIS spy. The film was never made as it poked fun at the British Secret Service; yet it contained the bare bones of what was to become “Our Man in Tallinn”, later Our Man in Havana. In 1988, anticipating my first visit to Soviet Tallinn, I wrote to Greene asking why he moved Our Man in Havana from Estonia in the 1930s to Cuba in the 1950s. Greene explained that a Secret Service comedy about an expatriate vacuum cleaner salesman who gets “sucked up” into espionage would be more credible in pre-Castro Havana, with its louche nightclubs and promise of tropical oblivion, than in Soviet-occupied Tallinn. He concluded: “I already knew Cuba and my sympathies were with the Fidelistas in the mountains… One could hardly sympathise with the main character if he was to be involved in the Hitler war.”

Of course, Cuba could not be more different from Estonia. Before Fidel Castro’s revolution of 1959, Havana was, effectively, a mafia fleshpot and colony of Las Vegas. Yet James Wormold, the salesman-secret agent of Greene’s Cuban “entertainment”, is not unlike Peter Leslie of the Baltic. Both men are old-fashioned merchant-scholars with a taste for books (and a fear of women). Christopher Hull, a lecturer in Spanish and Latin American studies at the University of Chester, argues convincingly in his fascinating exploration of the history behind Greene’s satirical spy novel that Wormold’s character borrowed from both Leslie and Greene’s “black sheep” elder brother Herbert, a fantasist who consorted with remittance men, confidence-tricksters and other compromised characters who inhabit “Greene-land”. Herbert appears, scarcely disguised, as the con artist-cum-salesman Anthony Farrant in Greene’s fine 1935 novel England Made Me. To Greene’s dismay, Herbert had acted as a spy for the fascists during the Spanish Civil War, and all his life displayed a deep moral turpitude and opportunism.

Cuba meant a great deal to Greene. Hull’s Our Man Down in Havana conjures the Cuban capital in all its tatterdemalion glory and Afro-Caribbean collision of skin colours and cultures. By Hull’s estimate, Greene visited Havana 12 times between 1938 and 1983, in the guise variously of holidaymaker, novelist, screenwriter, journalist and – possibly – intelligence gatherer. The author of the “iconic” Havana spy novel that foreshadowed the Cuban missile crisis of 1962 may himself have ended up snooping on post-revolutionary Cuba for SIS, Hull speculates. Certainly Greene was a provoking and paradoxical novelist, who delighted in exposing conflicting loyalties and shifting political allegiances in others, if not in himself. Perhaps, as the late Christopher Hitchens surmised, Greene’s most certain allegiance was to “betrayal”.

When the man Evelyn Waugh nicknamed “Grisjambon Vert” (French for “grey ham green”) visited Havana in 1954 to research his novel, the Batista regime was “creaking dangerously towards its end”: Castro’s revolution was just five years away. The dancing girls wore spangled headdresses and American tourists prowled the pre-communist city for cheap sex. With a taxi-driver as guide, Greene fathomed an underworld of anti-Batista revolutionaries, American double agents, dubious CIA operatives and a local sex artist called Superman, whose penis was said to be 12 inches long.

It is against this rackety background that Wormold is recruited into the Caribbean network of British Intelligence as Agent 59200/5 – the same number assigned to Greene when SIS despatched him to West Africa in 1941. In return for a British government salary, Wormold furnishes intelligence of a “big military installation under construction” in the mountains of eastern Cuba. The intelligence turns out to be based on the Atomic Pile vacuum cleaner user manual. Half a century later, in 2001, Hull reminds us, Tony Blair was taken in by “rough colour sketches” of presumed biological warfare installations drawn by an Iraqi “sub-source” code-named Curveball.

Greene’s 1958 novel (filmed soon afterwards by Carol Reed) vividly captured the Cuban capital’s atmosphere of surveillance and torture attendant on the Batista regime. Greene hurled himself promiscuously into the city’s grimy underbelly and sex industry. On his subsequent visits, Cuba was officially communist and largely emptied of its pimps and prostitutes. Fidel’s bearded Old Testament head appeared on billboards advertising a “new tropical variant of Marxism”, Hull writes. Greene found that Cubans revered Castro as a tough yet “comradely father figure”, whose overthrow of Batista had been nationalist, not socialist in origin. It was only after Cuban exiles abetted the CIA in the disastrous Bay of Pigs invasion in 1961 that Castro aligned himself with the Soviet Union. By then the Fidelistas were united in their fear and loathing of Uncle Sam. Castro closed the casinos, got rid of the go-go geishas and encouraged a defiant spirit as his people were subjected to ever more drastic belt-tightening.

In the end, though, Greene’s political views on Cuba and Castro remain “an enigma”, says Hull. Shortly after the Bay of Pigs debacle, the New Statesman published some doggerel by Greene titled “Lines on the Liberation of Cuba”:

Prince of Las Vegas, Cuba calls! Your seat’s reserved on the gangster plane, Fruit machines back in Hilton halls And in the Blue Moon girls again

The implied criticism of the Las Vegas-Cuba mobster connection (the “Prince of Las Vegas” is probably John F Kennedy) was at odds with Greene’s manifest relish for the seediness of Batista-era Havana. Whose side was Greene on? As it happened, Cuba under Castro did not revert to the lurid outpost of Las Vegas that Greene had imagined: the sainted El Comandante had immunised his people against “Capitalism Rampant”. Now that Castro has died, the scramble for greenbacks has created a new Cuban sex industry. The resort of Varadero is a Batista-style Caribbean Torremolinos complete with casinos and love motels. The beach (12 miles of paradise, with insects) heaves with pink and peeling leftist-trendies and sex tourists wearing Viva Fidel! T-shirts. The revolutionary spirit is giving out: all talk is of the “Yanqui dollar” and how to obtain it.

Sarah Rainsford covers much of the same ground as Hull in her book on Cuba. Our Woman in Havana, an amalgam of reportage and travel, follows Greene round his various favourite hotels and restaurants in Havana (the Moorish-revival Sevilla hotel, the Floridita bar). We get a good sense of the city’s photogenic decay, all collapsing promenades and salt-encrusted Catholic churches. Most Cubans, says Rainsford, practise a hybrid of Catholicism and the animist cult of Santeria, a low-alcohol version of Haitian Vodou (or voodoo, as it used to be called).

A former BBC Havana correspondent, Rainsford was in Moscow the day Castro died in 2016. Jeremy Corbyn spoke reverentially of the improvements made under Fidel in health and literacy: almost half of Cuba’s population was illiterate during the “capitalist Babylon” of Batista but now less than 1 per cent of Cuban adults are unable to read and write. Donald Trump, in contrast, called Castro a “brutal dictator”. Communist Cuba, in Trump’s estimation, had been nothing but a hellhole of sugar quotas, bread queues and police surveillance, with labour camps for homosexuals and the occasional implementation of the death penalty. All that is true, but, as Greene noted of Cuba, it is “not the whole picture”.

Ian Thomson’s books include “The Dead Yard: Tales of Modern Jamaica” (Faber & Faber)

Our Man Down in Havana: The Story Behind Graham Greene’s Cold War Spy Novel

Christopher Hull

Pegasus Books, 352pp, £19.99

Our Woman in Havana: Reporting Castro’s Cuba

Sarah Rainsford

Oneworld, 384pp, £9.99