KEEP ASKING!!! You ask some VERY intelligent and unresolved questions. PERFECT analogy! With my physical background, as well as my research/work with some noted professors, I think the answer to your question is "we don't know." But, for someone who isn't scientifically trained, you sure do know some deep inherit physics.
BTW: There are three theorized types of universes: flat, negatively curved (saddle) and positively curved (a balloon with the galaxies as "dots" on the outside).
From a
purely scientific standpoint, I believe the universe gets its "instructions" randomly. This is the most basic explanation as any sliver of "self-aware" order (of planets, stars, etc.) suggest design. I think a combination of point, integral (many points), and boundary (edge of box) characteristics influence our universe.
For example, the universe "started" as a infinitesimally small, infinitely dense
point of mass-energy in space that ultimately blew apart. As the energy "cooled," space-time condensed into photons (light particles), particles, atoms, molecules, and eventually galactic and universal systems.
The temperature of the universe, and the speed of its expansion is proportional. One theory scientists believe could lead to the universe's demise is something called the Big Chill. This says that since the universe (I will use your box example) is expanding quickly, eventually the galaxies will be too far from each other to provide "ambient" energy to surrounding area, and the universe eventually freezes.
Imagine an uninflated balloon. Now, imagine you could put "warm dots" on the balloon... literally fill the uninflated balloon with them. Now, blow up the balloon -- this represents the expansion of universe. You will also notice that the dots move further away. Now, as the balloon grows bigger, the "warm dots" wont give off ambient energies as easily, and the balloon will "chill"
For the boundary example (edge of box), imagine you make the box so big and massive that it literally collapses on itself and implodes into a black hole. This is the Big Crunch, another theoretical demise of our universe. It is for a flat universe.
Look these theories up, I took a few astronomy courses but I'm not a cosmologist

. Either way, I am pretty sure of the above.
Now, if you want to bring God into this... it all becomes very simple to explain



