Why does the black body radiation theory apply to many different objects? The standard theory of black body radiation that I am familiar with derive the Planck's law assuming first that we deal with a box in which the photon gas is contained. The box has a small hole in it so the light cannot escape once fallen into it - this realizes the 100% absorption property. However, the Sun or even other objects from our daily life are much more complex than that simple model and seem very distant from it. Nevertheless, the emission spectrum is well described by the same, universal Planck's law. Why? Can one derive that universal law using other model, with a different mechanism of absorption?
EDIT: Let me state my question in different, perhaps more clear way. There is nothing surprising for me in the fact that for example spectrum of the Sun do not fully agree with Planck's law, that is a typical situation for physics. When we model some physical system we always make idealizations, but in the case of black body theory the model of cavity with a hole is very simple and in microscopic sense totally different from for example stars. Without experimental verification I would not see much rational reasons for such a model to apply to more complex systems with different mechanism of absorption. But it apllies, not fully of course but it seems like photons inside a box reflect somehow thermodynamic properties of Sun - that is puzzling for me. We do not have a model of radiation of stars, we have a model for radiation of cavity with a hole, which is somehow valid for stars as well.
 A: The key is that the blackbody spectrum does not depend on any of the microscopic details of what produces it. Only the temperature. Like the idealised hole into a box at a fixed temperature, any body that is in thermal equilibrium at some temperature and absorbs all radiation incident upon it it, will emit blackbody radiation. 
The cavity with a hole is just a convenient thought (and sometimes real) experiment that enables that idealisation to be approached. The small hole  ensures that all radiation incident upon it is absorbed (providing you don't clad the interior with highly reflective material!) The box itself must have achieved an equilibrium temperature in order for blackbody radiation to emerge from the hole.
The requirement that all radiation is absorbed is what ensures that the details of the absorption and emission processes are unimportant. At thermal equilibrium all absorption and emission processes will be in balance (known as the Principle of Detailed Balance). If you equate rates for emission and absorption processes, then it turns out that 
the radiation field needs to have the form of the Planck function at the same equilibrium temperature.
The Sun is only approximately a blackbody because, although it does absorb all radiation incident upon it, it is not in equilibrium at a single temperature. The Sun gets hotter as you go into it, and at different wavelengths we can see to different depths. The reason it even approximates to a blackbody at all is that, thanks to continuum absorption by H$^{-}$ ions, the range of depths to which we can see is quite small, only covering about 1000 km, and the temperature does not change too drastically over this range.
A: An ideal black body has oscillation strength at all frequencies. If such a body is in thermal equilibrium it will radiate the Planck spectrum. Planck's box with the small hole, reminding of the photography of those days, is a simple model of such a body. 
Real objects are not perfect Planck radiators, as they cannot absorb and thus thermally radiate at all frequencies and always show some transmission, reflection and scattering. Their emissivity is not uniform. Planck's formula is nevertheless a very useful idealisation. The sun's spectrum is generated by a hot plasma and is quite close to 6000K Planck radiation. The sun is not in thermal equilibrium, so it should be no surprise that the agreement is approximate.
A: The standard theory of blackbody radiation is about thermodynamic equilibrium of quantum harmonic oscillators. It does not completely explain Planck's law, because for radiation density, it gives Planck's function plus unwanted $hf^3$ contribution, which is not observed and makes the EM energy in high frequencies diverge. So strictly speaking, the standard theory does not explain completely Planck's law - a bad term has to be excluded by hand first, and only then we get the Planck function of frequency for radiation intensity. This is related to the problem of "zero point energy" or "vacuum energy density"
https://en.wikipedia.org/wiki/Cosmological_constant_problem

Why does thermal radiation of Sun and cosmic microwave background behave according to Planck's law?

Because these are quite close to equilibrium radiation and Planck's law was designed to describe radiation spectral curve in equilibrium.
Historically, Planck believed thermal radiation could be in equilibrium with matter and he fitted data on such radiation with Planck's function of wavelength which bridges Rayleigh-Jeans formula (valid for low frequencies) with Wien's formula (valid for high frequencies) in the simplest of ways. After finding much agreement of his proposed function with the data, he set out to find some model of matter interacting with EM radiation that can produce that function within classical EM theory. He succeeded and published both classical and quantized model that recovers Planck's function.
Later, after quantum theory became the prevalent paradigm, his function was rederived using model of quantum harmonic oscillators (I think by Bose). Today that is the usual way to explain it - thermal radiation is due to photons in thermodynamic equilibrium. But it has the zero point energy problem and there are other explanations.
