There are more than 1,000 convicted Somali pirates in prisons around the world. Some of them end up in a UN-funded jail on the tiny island nation of Seychelles.

The Indian shopkeepers along the beach have never heard of the prison at Montagne Posee, but a villager tells me to drive above a deep ravine full of banana trees.

As the sea becomes a distant horizon and the road winds steeply, I stop to ask for directions from two men in yellow dungarees shovelling sand. As soon as the man with the shovel turns I can see that he is a prisoner.

He asks first for cigarettes, then for money, and then he says: "Just give me anything, I have nothing, I am from Somalia."

This is the pirates' prison, hidden high in the hills.

Hundreds of metres below, between two shimmering white beaches, upmarket tourists are paying up to £3,000 ($4,500) a night to stay in their thatched villas.

From Our Own Correspondent Insight and analysis from BBC correspondents, journalists and writers from around the world Broadcast on Radio 4 and BBC World Service Listen to the programme Download the programme

They know nothing about this prison wing, opened three years ago by the UN Office on Drugs and Crime.

Here, 66 Somalis are awaiting trial for piracy or, if already convicted, await deportation to serve their sentences back home.

Early the next morning I am in Victoria, the islands' capital, to witness an astonishing sight that is about to disappear forever.

In the heart of town is the beautiful black and white Creole courthouse.

Outside, lolling on benches are groups of handcuffed prisoners.

It is a sun-kissed Dickensian scene that I cannot imagine anywhere else.

Six Somalis, in flip flops and chained in pairs, are brought into the tiny court where a judge and nine lawyers clad in black and wearing wigs barely give them a glance.

These six were arrested last August hundreds of miles north - nearer Yemen than Seychelles.

They are accused of attempting to board a merchant ship and were captured by the Dutch navy with help from a Spanish helicopter.

Charles Brown is a barrister from Cumbria and one of two UK Criminal Prosecution Service lawyers who have been seconded to the attorney general's office in Seychelles to help prosecute pirates.

He says that they can look pretty shell-shocked when they first arrive in these lush islands, but describes the Somalis as a "cheerful and reasonably intelligent lot".

Brown needs to prove that these six were attacking a ship for private gain or that they were caught operating a pirate vessel.

Somali suspects are rarely found with guns although sometimes helicopters spot them throwing things overboard. They have been found with "pirate paraphernalia" - things like grappling hooks.

Most Somali prisoners though claim to be either economic migrants or simple fishermen, although, as Brown points out, their captured boats rarely have refrigeration or even fishing nets.

At one point so many pirates were being caught that they were being dumped back on to the beaches of Somalia.

But these days, with intensive patrolling of the Indian Ocean, more are being convicted.

Here in Seychelles, another 17 were recently flown home to a UN-funded jail in the relatively secure region of Puntland in Somalia, to serve sentences that mostly range between 10 and 20 years - 59 have already been tried and sent back.

Alan Cole, who works on the UN's Counter Piracy Programme, tells me that most Somalis are happy to be sent home to escape the prison diet of rice and tuna.

But he cites the story of one Somali who opted to stay on - to finish studying for a certificate in English.

He has received more formal education in one year in a Seychellois jail than in 20 years in Somalia.

Charles Brown believes that the war on piracy is succeeding, thanks to the efforts of navies and the close monitoring of boats leaving the Somali coast.

No armed merchant ship has ever been boarded and many now have a secure room or citadel to which crews can retreat while still operating their ships. And British investment in the courts is helping.

Something of a building boom is under way in Secyhelles at present, with Russian and Arab money contributing to some worrying developments.

Pristine forest and beaches are being built upon. The prison at Montagne Posee is not the only fortress overlooking the former slaver colony.

There are now ugly giant palaces built by the rulers of the UAE dominating the skyline over Victoria.

The old Creole courthouse - where justice is literally "seen to be done" - is to become a museum, and the court will move to a vast new Chinese-built property on the edge of town.

Meanwhile, as the astonishingly rich newcomers from the Gulf look down on their outsized boats in the harbour and the very rich tourists relax in their gated hotels, the Somali pirates are honing their gardening and footballing skills behind their very own walls.

How to listen to From Our Own Correspondent:

BBC Radio 4: Saturdays at 11:30 and some Thursdays at 11:00

Listen online or download the podcast.

BBC World Service: Short editions Monday-Friday - see World Service programme schedule.

You can follow the Magazine on Twitter and on Facebook