You should always know what is in front of AND BEYOND your target.
If there are places where people sleep, maybe positioning yourself where they are not behind your target is a good option? Depends on the floor plan, construction of the walls, and cover zones in the home. Right now, I'm the only one living on the 1st floor. Three live above me. I'm not that concerned about them getting hit by mine or an intruder's rounds in normal circumstances. I have a room light on a timer that's on all night in the center of the downstairs -- kitchen, living room & dining room are all lit enough to see into them. Need to be able to identify your target.
The best solution is to avoid putting places people might be sleeping in the line of fire. That includes neighbors. I have single-wall construction on the exterior walls. There's a vinyl fence between my home and both side-neighbors' homes. There's a 7' retaining wall to the back, and a road and 2 concrete block walls with fence insets before my neighbors in front. If I hit anyone unintentionally, it'll be a fluke -- just bad luck.
If I can be upstairs shooting down as someone climbs the stairs, that is my ideal situation. They can't move left or right once they are on the stairs, I have the high ground, and only the floor behind them to catch rounds that miss or pass through. I have a short wall at the top of the landing as well as the wall next to the landing for cover.
Sounds like this round you described is similar to some sizes of birdshot. 40 pellets must mean they are much smaller than 8 - 12 #00 buck pellets depending on shell length. I'd be concerned about its effectiveness stopping a threat if the person has on thick clothing or if enough projectiles miss.
My HD shotgun is a Keltec KSG 12 I keep loaded with #00 Buck in one mag tube and slugs in the other. #00 buck is chambered. I prefer having a round chambered for quick use rather than having an empty chamber. Racking the slide might make an intruder pause, but it also gives away your position, and it takes time to rack and aim. Personal choice, but there are pros and cons to both ready conditions.
When I only had my Mossberg 590, I alternated rounds: Birdshot, #00, #00, Slug, #00, Slug, ... This gave me a "weaker" round in the chamber just in case I did hit a wall I didn't want to over-penetrate. I could quickly eject that 1st rd if I thought #00 was needed. I figured if 2 rds of #00 wasn't enough, then try a slug. I like having options. in a tight spot, I might not remember which round I just fired, but at least I know they all have significant stopping power after the first.
The sound of a shotgun blast will likely send anyone still on his feet running, too. I doubt I'll ever need the KSG's 13 rounds, but better to have and not need...