the one time i found santuary under attack it had them spawning right in front of the MCs old house.
however other settlements like finch farm came under attack from ghouls and i was able to respond instantly (left the cave i was in and fast traveled) the ghouls spawned far up the road way outside the area and slowly walked, i had plenty of time to box in the NPCs and put a turret on top of the shack..
i then jumped up on top of the shack until the Ghoul AI realized they could not get to me and decided to run away. at that point i would jump down to anger them into following me close to the turret again and make them chase me all the way back to the staircase i would jump off of to get back on top of the shack where they would stare at me while getting gunned down for a bit before running away again (still getting turret murdered).
i repeated that quite a few times eventually killing them all.. then reloaded the game and set 3 turrets then reloaded and did the one again to save materials.
anyways if i had set up walls they would have 100% needed to get inside them in that situation. but most of the other attack encounters on other settlements dont seem to have that nice setup where they spawn at a distance and travel to the location... definitely something bethesda needs to address... i honestly think this is not something that should be "left to the modders". there should not be any creature spawn points for these events inside of the craftable area of any settlement.
sanctuary in particular, there is no point in guarding the bridge which is the only pathed route...