For now there’s no way to do such sophisticated masking ("scatter everywhere except where this part touches this other part’). We have future plans to support some sort of “volume mask” that could help in your case but that’s not there yet.
In the meantime, you can indeed use masks. For instance, you can draw a paint mask to touch up the distribution and exclude the interpenetrating instances. Another possibility is to use the walls of your box as area masks, which could help here since they are a bit tilted so this whould mask out instances near their base.
Yet another possibility would be to use the boundaries filter on the bottom face that serves as a host, so that instances do not appear close to its edges, which should reduce interpenetration.