Afghanistan is finally set to outlaw the sick 'bacha bazi' practice that sees young boys dressed up as women and sexually abused.

Heavy penalties are set to be laid out for the first time in a landmark move against the depraved act, officials in Kabul said.

It comes after it was revealed last year how the Taliban were exploiting rampant bacha bazi in police ranks to mount deadly insider attacks, exposing a hidden epidemic of kidnapping of young boys for institutionalised sexual slavery.

The revelations intensified longstanding demands by campaigners for Kabul to enact an incisive legal provision to curb bacha bazi - literally 'boy play' - which has seen a striking resurgence in post-Taliban Afghanistan.

An Afghan boy, who was held as a child sex slave, sits at a restaurant in a unidentified location in Afghanistan

A raft of punishments will now be listed in Afghanistan's revised penal code - from up to seven years in jail for sexual assault to capital punishment for 'aggravated cases' such as violating more than one boy.

'There is an entire chapter on criminalising the practice (bacha bazi) in the new penal code,' Nader Nadery, a senior advisor to President Ashraf Ghani, told AFP.

'The code is expected to be adopted any time this month. This is going to be a significant step towards stopping this ugly practice.'

A draft of the chapter seen by AFP, titled 'Driving children towards moral corruption', also states that bacha bazi victims cannot be prosecuted, a significant caveat in a nation where sex assault victims often face punishment.

Afghanistan's criminal law previously only prohibited pederasty and sex outside of marriage, which rights campaigners said did not sufficiently address the problem of bacha bazi.

'This chapter clearly defines bacha bazi as a crime, leaving no room for ambiguity,' Ghani's legal advisor Nasrullah Stanekzai told AFP, waving printed copies of the revised penal code in his hand.

Aside from police commanders, warlords, politicians and other members of the Afghan elite often keep 'bachas' as a symbol of authority and affluence.

The young boys, sometimes dressed effeminately with makeup and bells on their feet, can be used as dancers at private parties and are often sexually exploited.

Heavy penalties are set to be laid out for the first time in a landmark move against the depraved act, officials in Kabul said

AFP's investigation found that the Taliban were using the boys - keen on revenge and easy prey for recruitment - to infiltrate security ranks and mount crippling insider attacks on police in southern Afghanistan. The insurgents deny the claim.

Before the penal code, activists pushed for years for special legislation on bacha bazi, with scant hope of getting it through parliament as they suspect the practice is prevalent among lawmakers themselves.

'I have received calls from MPs that say they will never let a bacha bazi law pass in parliament,' said Soraya Sobhrang from the Afghanistan Independent Human Rights Commission. 'This is a battle to save 21st century slaves.'

The penal code is likely to be passed by presidential decree during the ongoing parliamentary recess. But Sobhrang worries that some lawmakers may try to water it down when it is later subjected to a parliamentary review.

Afghanistan has a poor record of enforcing similar provisions, including a law to eliminate violence against women and another to ban the recruitment of child soldiers, especially when the perpetrators are powerful.

'Explicit criminalisation in law of the heinous practice of bacha bazi is commendable, but implementation of laws in Afghanistan has been questionable,' the All Survivors Project, a global fact-finding effort into sexual violence against males in conflict zones, told AFP.

'How is the government planning to monitor, investigate and hold accountable those responsible for abusing boys under this new legal provision?'

Bashir, a relative of a 'bacha bazi' victim, is interviewed in Lashkar Gah in southern Helmand province

As Afghanistan's conflict escalates, critics have said there appears to be no will to act against abusive security officials who are seen as the lesser of two evils in the fight against insurgent groups.

Western officials have privately conceded to AFP that some Afghan commanders accused of bacha bazi are 'too strategic to be removed' from their posts.

But growing public scrutiny of the practice, once shrouded in shame and silence, is forcing authorities to act in some areas.

Earlier this month, the government sacked Shah Mirza Panjsheri, police chief of the volatile Dasht-e-Archi district in northern Kunduz province, after a video of his 'bacha bazi party' surfaced on social media.

'He was kidnapping young, beautiful boys and forcing them to dance in bacha bazi gatherings,' a Kunduz government spokesman told AFP.

'When we heard about this we dismissed him immediately,' he said, adding that he was the first high-ranking police official in Kunduz to be sacked for this practice.