It was the first time al Shabaab, under pressure from African Union, Kenyan and Ethiopian troops as well as U.S. drone strikes, had admitted to killing its own fighters for betrayals.
Al Shabaab, which is affiliated with al Qaeda, said last January that a missile launched from a drone had killed Bilal el Berjawi, a Lebanese al Shabaab fighter with a British passport.
Another missile killed four foreign militants south of the Somali capital Mogadishu in February, according to an intelligence officer.
"We have executed two CIA spies who were behind the killing of our great brothers," Sheikh Mohamed Abu Abdallah, al Shabaab's governor for the Lower Shabelle region, told Reuters on Sunday. "We also executed a third fighter who was proved to be a spy for the UK."
"Isak Omar Hassan and Yasin Osman Ahmed had fixed a device on Bilal el Berjawi's car and then he was killed by a plane in Elasha six months ago," Abu Abdallah said.
"The investigation is still continuing. If we find others, they will follow suit. We shall deal with them the way we dealt with the three executed today."
The Somali government says hundreds of foreign fighters have joined the Islamist insurgency from Afghanistan, Pakistan and the Gulf region as well as the United States and Britain. Some have senior positions within al Shabaab.
Al Shabaab were driven out of Mogadishu late last year and are struggling to hold on to territory elsewhere in the face of attacks by Kenyan, Ethiopian and African Union forces trying to prevent Islamist militancy spreading out from Somalia.
The United States has also authorised covert operations in the Horn of Africa nation in the past.
The Wall Street Journal reported that the Pentagon is seeking to send hand-launched drones to Kenya as part of a $40 million-plus military aid package to help four African countries fighting al Qaeda and al Shabaab militants.