(This will contain vague spoilers for episode 4 - nothing specific, but you'll learn the "general shape" of the episode).
Episode 4 has the same basic scenario as the Seven Samurai: farmers plagued by bandits ask wandering mercenaries to help. This basic scenario *really* works well - it's been redone in the Magnificent Seven (twice!), the Mandalorian and many others, in various eras and settings. It also works perfectly for an adventure. It works so well, and has been done so frequently, that it's almost like pizza. Pizza is great, but it's not original. It's also easy to do, but if you don't put any effort into it, it can be a pretty boring meal. So to avoid this being a ho-hum peperoni and cheese frozen pizza of a game, let's look at our toppings shall we?
The farmers/villagers/peasants/people who need help:
Getting these people right is important. They can't be abject cowards. They aren't resisting now because they *know* it's a hopeless battle. But hiring the PCs is changing the odds - there is hope now, and they will be willing to fight. They have to be sympathetic, and they also need a reason why they simply haven't fled their area. Maybe it's good farming land, they have a lot of infrastructure built (building huts and fences is a lot of work!). Maybe their ancestral burial grounds are nearby. Whatever it is, they have to stay. The villagers should have a bit of money buried somewhere to pay the PCs. Not a fortune, but for penniless sell-swords, enough to try. Lastly, making them interesting in some way certainly is recommended - they could be farming something unusual, have strange customs, even have wondrous or useful abilities (clearly, not battle abilities). Basic relations, petty rivalries etc. can also be fun. Every village has an idiot, after all.
This faction has to be dangerous, but not so dangerous it's ludicrous (if they are so bad-ass, why are they waiting their time picking on a small village?). They are actually *farming* the village: raiding periodically to steal food/valuable, but not doing so much damage to destroy it. They want to be back - in fact they probably have to, they need to eat! This indicates a certain level of intelligence and discipline... but they also aren't that smart - if they were, they would set themselves up as feudal lords and tax the peasants instead of raiding them. They need to be powerful enough that a 1vs1 fight with a peasant will result in the brigand winning, but a 1vs1 vs a PC should be a fight that the PC will win... however there are a lot of them, too much for the PCs to defeat by themselves. The peasants will have to help - but they are willing to do so if they are given hope.
The special weapon.
Things can be made a lot more interesting if the bandits have some kind of "special weapon". Maybe it's an ogre. A small cannon or a catapult. A spellcaster. A troll or some other big monster. A small tank. Simply their leader, or some unusual tactic. Whatever this is, it is what is giving them such a big edge over the villagers and is making them bold and confident enough to be raiding entire villages instead of travelers or isolated farms.
The party will have to deal with this special weapon to achieve victory. In the Mandalorian, Mando had spare blasters to equip the villagers with, but he didn't have some kind of "anti X gun" to simply eliminate the raider's special weapon. They needed a plan, effort and a bit of daring. Likewise, the party will have to be clever and courageous to neutralize the special weapon. If they do, and kill a few of the bandits, the rest of the villagers should be able to win relatively easily, if they are properly prepared that is.
The party needs to be powerful enough to make a difference, but not so powerful they can just crush the brigands while the villagers cheer and applaud. The timing of this adventure as part of your campaign matters. The party need the villager's help to win, or at the very least they need a good plan and good fortifications. I think level 2-4 would be ideal. Level 5 there is a bit of a power jump (in 5e at least) but it could still work, since in 5e low level creatures have better "to hit" numbers (a 2nd ed goblin has a thaco of 20. a 5e goblin has +4 to hit, ie the equivalent of thaco 16).
In the Mandalorian the "party" is higher level (I would describe Mando as level 5-7?) but fewer in numbers. An aspect that made the show interesting was that the party was "new" (the Mando and his ally didn't know each other at fist), but I think it would be preferable if the party, in a D&D game, have worked together for a few adventures at least. It *could* be a good starter adventure to unite the party, but this will be a bit more challenging to run. Even for an established group, this could mark the turning point in how the party sees itself - not just a rag tag of tomb robbers - but heroes too.
In the Mandalorian, Mando also had a special objective (defend Baby Yoda) but this isn't necessary for the scenario to work well. However, having some kind of vulnerable (but maybe useful?) NPC they have to protect on top of the general mission could be interesting?
The preparations and terrain.
The terrain should be interesting and varied - there should be opportunities for the villagers and party to put down crude fortification (barricades, a ditch etc.) and traps, funnel the enemy in subtle ways, hide a flanking team, whatever. The proper set up should give them a good edge over the bandits, or at least even the odds.
Hopefully, the PCs should be able to arm the villagers somewhat (missile weapons would be best) and train said villagers, so that their massed fire gives the edge to the party/villager alliance. Even improvised spears could help, as some of the bandits will try to close in and rush the barricades. Besides basic weapon training, the villagers should also learn what their part in the battle plan is. The kids shouldn't fight directly, but maybe they can be used to put out fires, activate traps and otherwise help. Almost everyone can pitch in, but the villagers won't accept some of them being used as cannon fodder.
It is possible that the village also has a "special weapon" of its own, but clearly it's not usable at the moment - something has to be done to assemble it, activate it, repair it, recruit it, create it, whatever. Perhaps they are beekeepers and some of the bees could be weaponized? If the party comes up with a clever idea, let them! It's important that this be a winnable fight, but it doesn't have to be the way you thought of as a GM, just a way that is plausible and fun.
For the love of god, don't roll for every single peasant and bandit! It will take forever and not be fun. The battle should be narrated in the background, and the PCs should turn the tide by reinforcing areas that are buckling, and by taking out the "special weapon". Once the special weapon is out and a number of bandits have been killed, the rest run away, not to return - they know this village is too tough for them now. They aren't fanatics, they just wanted to steal their food or valuables.
The party gets their reward and moves on! Will some of them decide to stay behind and become farmers? Why not? It could be a good point for someone who doesn't want to keep their current character to retire said PC and start anew.
Another alternative of course is that this village becomes a base of operation. Maybe there are other adventures to be had in the area?
If you get most of these ingredients right, you can have a few very good sessions with this scenario. It won't be the most original, but everyone loves pizza.
Special thanks to Words for Yellow for discussion and feedback on this topic!