To address your confusion, the reason the one pushes the other one out is due to the very fact that they have colliders and the way how colliders work.
I am assuming you are looking at your collider’s wire frame and assuming that if the sphere is INSIDE the frame and not TOUCHING the frame, then the OnCollision won’t get triggered and your sphere will be left alone. Unfortunately it doesn’t work this way. The entire content of the volume inside the wireframe acts as the collider. When an external object first enters a collider, it triggers a collision. After that, it triggers an collissionstay event so wether it first touches or wether it is inside, it is colliding.
Now if you consider that the very point of a collider is to keep solid objects out of each other it makes sense that if the sphere is inside the cube that the cube will push it out. Also, just so you know, when you instantiate an object, that instantiation counts as a OnCollission event.
Consider this: If you shoot a bullet at wall and you set the speed to be 1000 m/s and the wall is 1000 m away. This means it will take the bullet 1 second to get there. This means the bullet has to travel 1000 world units in 1 second. Now let’s say you get a constant 25 frames p/s refresh rate, this means the scene will be drawn 25 times. Thus, each frame, the bullet advances 40 world units. If you have a target between your gun and the wall and it is 1m thick and positioned 90m from you, your bullet will never hit the target. The bullet will be drawn at 80m and at 120m but will never be drawn at 90m so it never collides and thus the on collisionenter is never triggered so the target is missed completely.
Conversely, if the target is 20m thick and thus stretches from 110m to 130m, this means the bullet will be drawn outside the target at 80m the one frame and the next frame the bullet will be drawn completely inside the trigger. Even though it is now completely inside, the fact that it wasn’t inside the previous frame means it now triggers a collision enter.
Same with your code. When you instantiate the sphere, it wasn’t inside the box the last frame so this frame it causes a collision enter event which then pushes the foreign object outside of it’s bounds. To prevent this, syclamoth had the right answer. Instead of having a cube with a collider, you need to have 6 separate colliders. Place a collider on each wall so when you are inside the box, you are not touching any collider. Conversely, when you try to go outside the box, you WILL be touching a collider THEN and will not be allowed to do so. Getting 6 colliders to neatly touch without constantly calling an oncollisionstay with themselves means you should leave small gaps… it’s just a pain. Don’t do it.
The simplest way to do what you want to do, is to create a box with 6 separate sides (i.e. in your editor program, don’t just make a cube and think you are done. Make a cube and then make each face a separate object then reverse the normals so the inside of the box is the outside of the box).Now when you import the model each face will get it’s own collider and your problem is taken care of.
Alternatively (I have never done this, but the logic behind it makes sense) follow his other example, make a cube, reverse the normals on the entire model then when you import the model into Unity, give it a mesh collider and this should solve your issue also.