So I've got a medieval fantasy world where humanity has been forced to live exclusively in fortified towns and city states because of attacks by monsters. These monsters are not kaiju level in size so smaller and more populous, think Grimm from RWBY. They do not actively seek to annihilate humanity but will hunt humans as a food source if there is an opportunity. The monsters will also attack livestock. The monsters can be eaten themselves but hunting them is dangerous for obvious reasons.
Trade with other towns is possible but that would require a large amount of protection.
My question is how would these societies manage to get enough food to survive since the more land they use to grow food the more guards they will need to protect this farmland from monster attacks. What methods could they use to get enough food and survive the monsters?
First edit:
The types of monsters will be extremely varied, big, small, fast, slow, carnivorous, herbivorous etc. Most will be modified versions of real world fauna but some will be taken from mythology or created from scratch. Most are still dangerous.
Second edit:
Getting a lot of requests for clarification and some answers treating it just like real world so here's some new info.
On the monsters: The monster population is massive and many of them are apex predators. They drastically out power humanity so simply wiping them out or leaving a shepherd boy in the fields with a sling is not a possibility. It's safe to say they've overrun the earth even though that's technically not correct as they were always there. Humans are much lower in the food chain than on earth.
The monsters have always been there and did not just turn up one day, they evolved naturally alongside other creatures including us. Species of monsters have evolved everywhere on earth that can support life, so seas, deserts, islands, polar regions, you name it. No environment is completely safe.
While intelligence varies greatly just like the real world, many species have displayed decent intelligence and problem solving, sometimes even use of makeshift tools.
Domestication is a possibility but would be very limited. There is a really good reason the real world doesn't have your friendly neighbourhood tiger. Most monsters are simply too dangerous and/or smart to be bossed about by the obviously inferior humans.
Monsters have their own stable food chain and so are not completely dependent on eating us and won't die out if we somehow successfully manage to stay away from or fend them off for a sufficiently long period. They are not exempt from this food chain and monsters will attack and eat other species of monsters.
The Herbivorous and Omnivorous monsters who would eat crops are no less of a threat. Many would attack humans if approached and would not take kindly to humans trying to get rid of it (you try telling a monstrous bull or herd of monster buffalo to piss off, see how it goes).
On alternate methods of transport: Several people have suggested alternate methods of transporting goods between different places.
Hot Air balloons: This could conceivably work but that has its own problems, there are plenty of airborne monsters that are more than capable of attacking these, also, the technology is several hundred years past my medieval setting, it's possible that the limitations I'm placing on these people with the monsters would result in their invention early though.
Tunnels: Tunnels are expensive and difficult to create in modern day. My medieval societies with their limited resources and economies would be completely unable to do this. Maybe if there were dwarves, but there aren't.
Sailing: This would very likely happen but there are aquatic monsters that can attack and do serious damage to ships.
So basically all forms of transport must be done with extreme caution.
On different methods of stopping them:
Fences: These wouldn't work. There are so many ways to get past fences, especially if determined, burrowing under, flying or jumping over, if big enough or with sharp claws possibly just going straight through it. If used, fences would be used to keep in ordinary livestock or as a deterrent/method of slowing monsters down.
Attack on Titan style walls: This has been suggested and it wouldn't work. If you've gotten far enough into AOT (I won't spoil it) you'd know that the walls were not created by conventional means. There is no way for my people to manage this feat.
Game of Thrones style The Wall. Just like the AOT walls, this isn't a possibility. Remember that that wall took 8 thousand years to build, is only possible in that climate with the extreme cold and they're barely able to manage it against the more mundane attackers.
Ordinary walls: Could work if done properly
Traps: Would work but more measures would be required on top of that.
Deterrents (thorns, poisons, foul-smelling plants): These would work on the smaller monsters but not all. Some would be big and strong enough to not care or smart enough to figure out deceptions and ways round. So can be used partially but other measures will be needed.
Natural obstacles: My people would most definitely make use of these to avoid extra work to make fortifications. Islands are a great idea if they're small enough that they can occupy the entire island and there isn't any wild space for monsters to take hold.
To that one guy who suggested time travelers bringing advanced technology as the plot demands, I have no words.