Hang on, are we talking about 'Trapped' by James Alan Gardner? Or the 'Trapped in a Dating Sim' light novel series? Could also be 'Trapped', the 2022 thriller by Marc Bell. The request is a little ambiguous, but if we're going with the most common reference I've seen in book circles lately, it's probably Gardner's 'Trapped' from 2007. The core idea is that an entire town—Morganville—gets suddenly enclosed by an impenetrable, invisible force field. Everything stops: electricity, radio, cars. They're cut off completely.
So you've got this micro-society crumbling under the pressure. The main character, Tory, is a high school senior who was already an outsider, and she becomes a focal point as people look for someone to blame or a leader to follow. It's less about the sci-fi 'how' of the barrier and more about the 'what now' of human nature. The plot spirals from confusion to scavenging to forming factions, with Tory trying to hold onto her small group of friends while the town's sheriff tries to impose a brutal new order.
I always thought the most gripping part was the slow reveal that some people might have known this was coming, and that the barrier might not be an accident. It turns a survival story into a conspiracy puzzle. The ending leaves you hanging, which fits, because it's the first book in a series.
Some fans get frustrated with the pace, but for me, the gradual unraveling of civility was the whole point.