The box with interior walls painted in black is not the blackbody. The realization of the surface of a black body is the surface of a small hole (small with respect to the size of the box) on the wall of such a box.
As clearly stated in wikipedia page:
Any light entering the hole is reflected or absorbed at the internal surfaces of the body and is unlikely to re-emerge, making the hole a nearly perfect absorber. When the radiation confined in such an enclosure is in thermal equilibrium, the radiation emitted from the hole will be as great as from any body at that equilibrium temperature.
When modeling the set of electromagnetic (em) waves in the cavity, there are a couple of points which allow significant simplifications:
- provided the cavity is large enough, details of the em radiation inside become less important. In a more technical words, the density of states at thermodynamic limit becomes independent on the shape of the cavity and on the boundary conditions. Therefore, one is enabled to chose the simplest case, without loss of generality.
- When interested toin equilibrium properties, the precise mechanism at the basis of thermal equilibrium becomes irrelevant, thus one has not to take into account explicitly the real absorption/emission by the atoms on the wall. The final effect of thermal equilibrium (whatever is the underlying mechanism) is taken into account by the equilibrium probability function for the em modes. Interestingly, a similar approach is used when dealing with the equilibrium properties of the perfect gas. Strictly speaking the perfect gas does not have a mechanism for thermalization (no collision between molecules). What is implicitly done in the usual statistical mechanics treatment is to take for granted that an unspecified mechanism exists allowing the system to reach thermal equilibrium, even if it is not explicitly present in the Hamiltonian. It is enough to make the hypothesis that the mechanism exists and is effective in establishing thermal equilibrium. At that point it can be switched off.