A teenager who admitted stealing material to make a bomb has been detained for five-and-a-half years.
Stuart Lee, 19, stole the ingredients in an "out of control" three months.
Gloucester Crown Court heard Lee had "gone off the rails" as a teenager following a family tragedy and had started using drugs.
Lee, of School Road in Pillowell, near Lydney, pleaded guilty to a string of offences carried out when he was aged 18 last summer.
Prosecutor Julian Kesner said Lee had made a "fake" nail bomb out of a pressurised container, nails and snooker balls.
Search for stockists
Mr Kesner said Lee took several pictures on his mobile phone of the device and then told friends he was going to set it alight in a railway carriage, which he later did - causing "relatively nominal" fire damage.
The court heard Lee then carried out research on the internet on formaldehyde, which can be used in bomb making, then set about searching for local stockists of explosive materials.
"In September last year he had progressed from making that fake bomb to stealing ingredients capable of making a lethal explosive device," Mr Kesner said.
The court heard he stole ingredients which, if mixed together, are capable of causing an explosion with the release of hydrogen cyanide gas."
The most serious charges were arson and possession of an explosive material without lawful excuse.
Changed for better
He also pleaded guilty to burglary, possession of an offensive weapon, drugs offences, attempting to pervert the course of justice, attempted robbery and twice failing to surrender.
Lee asked for further offences of burglary and handling stolen goods to be taken into account when he was sentenced.
Fiona Elder, defending, said since Lee has been remanded in custody his personality had changed for the better after stopping taking mephedrone.
Judge Jamie Tabor QC sent Lee to a young offenders institution for five-and-a-half years
The judge told Lee he was "completely out of control" in the summer of 2012 and was a one man "crime wave".
"You had a very unhealthy interest in explosive devices but not only did you research those devices, you wanted to find out where those substances were stored."