There's not a warship for miles, a small pirate skiff is speeding toward you and there's no way the creaking tub you're on can outrun the bandits. How long do you wait before you shoot?

It's just one of many possible dilemmas facing an increasing number of private security companies who offer armed escorts — known in the industry as "shipriders" — from Somali pirates.

The few companies that have begun offering armed escorts say their services have become increasingly popular since the April hijacking of the American-flagged Maersk Alabama, particularly among U.S. shipowners. One company — Hart Security UK — has reported a fourfold increase in escorted trips since it began offering them in October.

But legal problems abound for ships that carry guns.

The first hurdle is making sure the countries where ships embark and disembark the weapons will allow them to do so — a legal nightmare in corrupt Middle Eastern ports with terrorism problems.

Then there's the issue of which law applies onboard the ship if a weapon is discharged: the shooter's nationality, the law of the country whose flag the ship is flying, or the territorial waters of the country the ship is in.

In at least one case, a private security consultant said, an armed team had rented weapons from the Djibouti government then was forced to drop them over the side of the ship to avoid illegally importing them into the country where they were due to disembark. The consultant asked for anonymity because he did not wish to compromise his business.

Kenneth C. Randall, the Dean of the University of Alabama School of Law and an expert in international piracy law, said there were complex issues for companies providing legally armed private guards.

"Commercial vessels have the right of innocent passage through most coastal waters. Some nations might say once you're armed, you're no longer innocent," he said.

Many questions have yet to be tested in court: should ships wait for the pirates to fire before returning fire? Is it still self-defense if the pirates are not firing at the shooter, instead aiming at the captain's bridge? What happens if the pirates are attacking from a "mother ship" — a vessel that has already been pirated — and there are civilians onboard being used as human shields?

That's the nightmare scenario the Indian navy faced last November. Pirates hijacked a Thai fishing trawler then apparently fired on an Indian warship. The Indians returned fire, turning the Ekawat Nava 5 into a massive fireball and killing 14 of the 15 crew as well as the pirates. The surviving sailor spent six days adrift in the shark-infested ocean before another ship picked him up.

There is no public registry of all the different companies providing armed guards to ships. Some, like Lotus in Yemen, did not return calls seeking comment.

But other companies interviewed in Britain and America said interest in the newly emerging market has been stoked by the recent series of high-profile hijackings, although only a small proportion of ship owners have inquired about having armed guards onboard so far.

U.S. private security company Templar Titan is providing shipriders and has been doing around 15 escorts per month through the Gulf of Aden a month since it began the service four months ago; the teams are armed on between half and three-quarters of the passages.

Lew Knopp, who heads the company, said the maritime division of his firm has increased from 3 people to 30 within the last year.

"We are directly consulting with the U.S. government on issues of piracy, especially in the Gulf of Aden and we have attorneys reviewing and co-ordinating efforts so they fall within international rules and regulations," Knopp said. He declined to give further details, citing operational security.

Despite the challenges, interest in arming ships has shot up following the Maersk Alabama hijacking, said Hugh Martin, Hart Security UK's general manager.

"We've had a substantial increase in inquiries," he said. "There is a lot of interest from companies that are American-owned."

Martin said that when the company began offering armed escorts in October, they were doing around 5 escorted trips through the Gulf of Aden a month. Now they do around 20 trips a month and also offer the services of two vessels with helipads that accommodate up to 28 people each. They are usually hired by groups of ships to act as an escort, Martin said, and are in use every week.

He says Hart uses Yemeni guards and makes sure the weapons are legally imported and exported at both ends of the ship's journey.

"The amount of effort we put in to ensure we are legal is colossal," he said.

Britain's Maritime Asset Security and Training (MAST) is also offering armed guards, either ex-British naval or special forces personnel. MAST has established a subsidiary in Djibouti to provide a security transit service at the western end of the Gulf of Aden, which also allowed it to license the use of firearms under government approval. Phillip Cable, the director of MAST, says the company is providing the service between 30-35 times a month but only between 10-15 percent involved armed protection.

Other companies like Olive, which guards Shell in Iraq, or maritime security firm Drum Cussac say the legal implications of having armed men onboard commercial shipping are still too unclear.

"What do you do if you shoot a pirate and he surrenders to you?" asked Crispian Cuss of Olive.

But many companies are keen to diversify from Iraq and Afghanistan and are interested in the possibility of training a Somali coastguard. Recent donor conferences focused on the need to build up Somalia's ragged security services, both to combat piracy and the influx of hundreds of foreign jihadi fighters dedicated to the overthrow of the U.N.-backed government.

The millions pledged to Somalia represent a potential goldmine. Pirate attacks have dropped out of the news but still occur almost daily, and around 200 people have been killed on land in the latest round of fighting, which experts fear may lead to the establishment of an Al Qaeda foothold on the Horn of Africa.

But before countries agree to spend money on a coastguard, they want to see safeguards to ensure the training or weapons they provide are not turned against them later. A U.N. report issued last December estimated over 80 percent of Somalia's soldiers and police deserted along with weapons and vehicles. A U.N. program to train 10,000 Somali police was frozen due to the high rates of desertion and corruption, which was so bad police were sometimes left without boots or belts and went unpaid for months at a time.

"If we don't learn from that failure we'll repeat the same mistake," said Rashid Abdi, a Somalia analyst at thinktank International Crisis Group. "Accountability should be critical to the donor community and it should ensure that the current project is not being as mismanaged as the previous one."