add cube
add UV Sphere
add geometry nodes to cube
scale down uv Sphere in edit mode
use this node tree
- play a little bit with distance so that the spheres don't touch each other
result:
UPDATE
add a cube, delete top face and add solidify modifier, rigid body, passive
add a uvSphere, give it a rigid body, shape: Sphere, Sensitivity: collision margin: 0
copy that sphere as often as you need it and move it so it doesn't intersect with the others
run the animation until you are satisfied, then select all spheres and press object->apply-> visual transform
now you can delete all rigid bodies and do whatever you want to do with it
result:
video tutorial: