The case of the sun is not very different to that of Earth: The stuff that makes up both is mostly opaque (plasma for the sun rock for the Earth), but at some point both bodies become transparent (in the Sun when it is cold enough such that electrons recombine with atomic nucleus and form gases, in the Earth at the base of the atmosphere), the base of the transparent layer and the transparent layers themselves emit electromagnetic radiation according to their temperature following Planck's law of black-body radiation, and absorb pretty much any incoming radiation regardless of its wavelength.
The concept of black body (or gray body) only refers at the fact that a body absorb all (or a constant fraction for a gray body) the energy it receives regardless of the wavelength (color), therefore it looks black. Similarly, it must emit in all wavelength too, with the intensity at each wavelength (color) following Planck's law of black-body radiation.
Therefore a mirror is not a black body, neither is a fluorescent lamp, nor a tomato. Because a tomato reflects red light more than green. However, if the thermal balance of a tomato is mainly controlled by the exchange of infrared radiation, you can treat it as a black body, because it acts as one in the infrared spectrum (i.e. if your eyes were sensitive to infrared radiation only, a tomato would look black or gray). In the same way, despite the fact that Earth isn't black, it can be approximated to a black body and with such approximation you can get very accurate results of its energy balance.
Going back to your point. Black bodies can have internal energy sources (like the Sun), and in the absence of the Sun, the hot interior of Earth would also act as an energy source and the Earth would emit more energy than it receives, in the same way the Sun does.
So anything can shine radiation onto a black body, that is precicely because it is a black body and absorb all kinds of electromagnetic radiation. I hope this clarifies your doubt.