An actress dressed as a killer doll with bloody scratches on her face is perched on a handrail, smiling wide as if she can’t wait to play with me. Just looking at her gives me the creeps. This is the entrance of Machine Shop, a haunted house attraction at Eastern State Penitentiary in Philadelphia. Inside the attraction, zombies with shaved heads lead me through a maze of old, rusted machines and chopped legs and arms. They even lock me inside a cage. But I chose to be here. It’s Halloween, and I want to be scared.

What is it about fear that we like? A lot has to do with how our bodies react to being scared. Some of the same chemicals released by your brain during a scary situation — endorphins, serotonin, and dopamine — are also released when we experience joy and excitement. As I was walking through the attraction, my heart was beating fast, I was sweating, and I was ready to run — an adrenaline rush. And when I got out of Machine Shop, finally able to breathe again without nightmarish zombies jumping out at me, I was rewarded by feeling like I’d made it through something very dangerous.

These positive feelings were only possible because I knew I was in a safe space. I knew the trained killer doll and zombies weren’t going to hurt me and I knew that the chopped legs and arms were fake. I was also wearing a red glow necklace, which meant I had voluntarily opted in the more "immersive" experience — giving actors permission to touch me and lock me in cages. At any time, I could take the necklace off and I would be left alone. Knowing I had control over the situation was key.

"The difference between trauma and resilience is preserved agency," says Margee Kerr, a sociologist who studies fear. "When people know that they’re in control of the experience, then they can reap the rewards of enduring. When that control is taken away, it can turn into real trauma."

Not everyone is a thrill-seeker, of course. Some people get more of a kick out of the dopamine released during scary situations, for example. And someone who lived through trauma or didn't have good experiences with horror movies as a kid might not enjoy fear as much.

For me, Machine Shop wasn’t traumatic, but it still was scary. The location itself is spooky. Eastern State is an 11-acre penitentiary that opened in 1829 and closed in 1971. Now it’s a museum during the day, but it still has the gritty feel of an abandoned building: long empty corridors, peeling paint, crumbled walls, and tiny cells with rusted bed frames. And on fall nights, the penitentiary turns into the Halloween attraction called Terror Behind the Walls. (Machine Shop is one of six attractions.)

The Verge went to Eastern State to learn more about the science of fear and why we actively pursue it this time of year. I was the guinea pig for the sake of Halloween and science. I screamed, sweated, and had mini heart attacks throughout, but I won’t lie, I enjoyed it.