WHEN Omar returned home after 40 days in a boot camp run by Islamic State, it was obvious something had snapped. Once a quiet boy and a fan of SpongeBob SquarePants cartoons, Omar, 12, had become aggressive. He told his mother to stop wearing make-up, refused to greet her female friends and became angry when she tried to bathe him. “I was scared to wear a T-shirt inside my own house,” his mother, Amina, says. “He told me these things were forbidden under Islam. They washed his brain.”

Omar died shortly after his last visit home. Trained by IS as one of its inghimasi—shock troops sent into battle with assault rifles and suicide vests—Omar was killed fighting Syrian government forces in the eastern city of Deir Ezzor, not far from his home, six months ago. IS allowed his mother 15 minutes with her son’s body before burying him in a grave that she was forbidden, as a woman, from visiting.

Amina’s anguish is sharpened by her relationship with the man she blames for her son’s death. Now a refugee in Turkey, she says her husband, who had become enamoured with IS’s ideology shortly after the group stormed their area, encouraged Omar to join the extremists. “He told me I should be happy when Omar died; that he was in paradise,” she says as tears slide down her face. “It felt like someone had extracted my soul.”

The ultra-violent jihadists have recruited thousands of children in Iraq and Syria. Like Omar, many have been dispatched to the front to die. Others work as spies, bomb-makers, cooks or prison guards. In extreme cases, children have executed prisoners, sawing off heads with knives or firing bullets into skulls. Thousands more have been exposed to the group’s warped ideology at IS-sponsored schools.

The jihadists portray children as the future of their “caliphate”, who will ensure its survival. Yet the jihadists are sending more children to die than ever. Under pressure from American-backed ground operations, IS’s territory in Iraq and Syria is shrinking. To replace the mounting toll of dead adult fighters, the extremists are recruiting more children. In January 51 children blew themselves up in Mosul, says Mia Bloom, a terrorism expert at Georgia State University. Many more will die in the battle for the Syrian city of Raqqa that has just begun. Pressed on the battlefield, military expediency has trumped IS’s dreams of nurturing the next generation of holy warriors.

Still, many child soldiers will outlive the caliphate, and will pose a security threat long after its demise. European intelligence services are worried: children taught to build bombs and hate the West may find it easier than adults do to slip across borders or past security services. In Iraq, the government is ill-equipped to demobilise thousands of trained child soldiers whose minds have been twisted by ultra-violent ideology. In Syria’s chaos, former “cubs of the caliphate” may make easy recruits for the country’s many other jihadist groups.

The question is how to tackle this looming danger. One bleak option is to kill as many of the child soldiers as possible on the battlefield, and imprison the rest. History suggests, however, that this turns prisons into breeding grounds for the next generation of militants. About 2,000 children already languish in Iraq’s jails, accused of working with IS. These detention centres are poorly equipped to cope with radicalised youngsters. Far from receiving specialised care, child detainees interviewed by human-rights groups say Iraqi security forces have tortured them. Abused and abandoned, these children will grow up to hate the state.

The far better option is to try to rehabilitate the child soldiers who survive. Re-schooled and given jobs, children are less likely to rejoin armed groups, radicalise their peers or create their own insurgent groups. The UN-led rehabilitation programme in Sierra Leone, for instance, has been widely praised. But what sounds good in theory will be difficult in practice. Many of the children will return to communities whose members despise them for joining a group that butchered and plundered its way through their towns and villages. “These children aren’t victims. They have murdered our relatives and friends. They deserve death,” said a rebel commander who fought IS in Syria. Other children will refuse help, terrified of being arrested by Iraqi security forces or killed by IS for deserting.

The many ways IS recruits children will make rehabilitation programmes even harder to design. Some have been snatched from orphanages or kidnapped from minority sects. Egged on by peers, others have been seduced by the group’s promise of adventure, money and power. Parents have sent their children in return for food, cooking gas and a monthly stipend of $200; others, like Omar’s father, because they believed in IS’s ideology.

The role played by families in the recruitment process is particularly damaging. In other conflicts, the parents of child soldiers have eased the transition to civilian life. In El Salvador, for example, 84% of former child fighters said their families were the most important factor in their reintegration, according to Biomedica, a journal. But in Iraq and Syria many families have at times encouraged their children to join the militants, some in the grisly belief that their child’s death in battle clears their own path to heaven.

It is tempting to see IS’s use of children as unique among militant groups. In July 2015 the jihadists released the first video of a child beheading a captive (a pilot in the Syrian air force). In early 2016 a four-year-old British boy, whose mother brought him to Syria, became the first European child to feature in an execution video: he was filmed pressing a button that blew up a car with three prisoners inside. In another video, boys race through the ruins of a castle, competing to see who can kill the most captives. Others have been photographed clutching severed heads, their fathers beaming with pride next to them.

Although the creativity of the violence may be novel, the degree of brutality is not. Child soldiers in other parts of the world have killed their own parents, cut the lips off captives and amputated limbs. It is not the barbarity that is new but rather how the violence is documented and disseminated. Nor are the reasons why a child joins IS unique. In other conflicts, too, child soldiers have been plucked from the poorest communities, easy prey for religious leaders skilled at turning feelings of anger, exclusion and revenge into violence.

Plans to offer apprenticeships and vocational training to children who have fought with IS are now being considered in Iraq. The caliphate’s cubs may one day be fixing air-conditioning units, cutting hair, mending cars and repairing mobile phones. But all this is a long way off. Creating jobs in a country with high youth unemployment and endemic corruption will take time and money. Schools are starting to open in areas once occupied by IS, but staffing them with qualified teachers who can deal with complex issues like radicalisation and psychological trauma will be difficult. Governments in the West have begun to show an interest in rehabilitation programmes. Whether today’s jihadist cubs grow into tomorrow’s lions will depend largely on how long this interest lasts.

This article was modified on June 28th to credit the work of Mia Bloom in this area.