Up until its demolition in 1817, the Tolbooth, located in front of Giles Cathedral on the Royal Mile, Edinburgh, was the cities oldest prison. Records show that it was in existence as early as 1403. Meaning Tall Prison in Old Scots, the Tolbooth was a large towering structure similar in appearance to its counterpart the Cannongate Tolbooth (now a museum), located half a mile down the same street. It was here that the cities criminals spent their last nights, before being taken to their place of execution, which was often on a platform built onto the side of the building. As imprisonment was not used as a punishment until much later on, the Tolbooth was not designed for long-term imprisonment, but rather as a place for prisoners to be kept while awaiting their punishment, usually corporal. The site where the Tolbooth once stood is marked now with a pattern forming a large stone heart in the cobbles, known as the Heart of Midlothian. It is considered good luck (and bad hygiene) to spit on the heart, and thus avoid the bad luck of those who were executed there.

Despite countless attempts, very few actually managed to escape the prison. One of those few was James Hay, the eighteen year-old son of a stabler who, in November 1783, was arrested for robbery and imprisoned in the Tolbooth awaiting his sentence of death by hanging. Days before his execution, he was visited by his father, who brought with him a bottle of spirit. As night fell, the visiting families of the felons on death row were asked to leave, however Hay's father persuaded the prison jailer to join him in a drink. When they finished the bottle, the father suggested to the jailer that another bottle should be procured, and that the jailer was just the man to do this. Agreeing, the jailer staggered out into the night, neglecting to lock the inner door in his drunken state. James followed, as his father had planned. However, as he reached the outer door, it was slammed shut by the outer warden. At this point, James's father called out "Turn you hand", the well-known command used by the jailers to open the gates. The warden obliged, and James rushed out of the prison and into the night. While the guards were distracted by his father, James made his way to Greyfriars Churchyard, where, using the key with which his father had provided him, opened the tomb of Sir George MacKenzie, long believed to be haunted by the infamous MacKenzie Poltergeist. For six weeks he stayed in the tomb, provided with food and drink by students of George Heriots school just over the wall from the tomb. As Hay had been in attendance at the school, the students felt obliged to help him. On 24th November 1783, the following article appeared in a local newspaper, The Edinburgh Advertiser:

ESCAPED FROM THE TOLBOOTH IN EDINBURGH
James Hay, indicted for Highway Robbery, aged about 18 years, by trade a glazier, 5 feet 10 inches high, slender male, pale complexion, long visage, brown hair cut short, pitted a little in the face with small-pox, speaks slow with haar in his tone, and has a mole on one of his cheeks. The magistrates offer a reward of Twenty Guineas to any person who will apprehend and secure the said James Hay, to be paid by the City Chamberlain, on the said James Hay being recommitted to the Tolbooth of the city.

Six weeks later, when the uproar had died down and the search had been called off, James Hay finally exited the tomb and left the city forever.