We discuss possible mechanisms for indirect exchange between ferromagnetic ␦ layers of transition metal inserted into a semiconducting host, taking into account the role of carrier confinement at these layers. We show that the Ruderman-Kittel-Kasuya-Yoshida mechanism is not the ultimate explanation for an interlayer interaction and an efficient interlayer coupling can be mediated by the undoped semiconducting spacer due to virtual excitations across the energy threshold. We emphasize the important role of quasi-two-dimensional spin-polarized states inside the bulk energy gap, which are caused by the confinement and the exchange scattering of itinerant electrons by the ␦ layers. Quasiparticle excitations from these states to the band edge of the spacer contribute to the interlayer coupling even for a wide gap semiconducting spacer. Our analysis shows that the related exchange integral can change its sign at some "critical" spacer thickness, i.e., a ferromagnetic coupling mechanism is active at short distance between ␦ layers and an antiferromagnetic coupling mechanism is active at large distance. Taking into account the effects of crystal symmetry, we also obtain the expression for the interband coupling energy in the case of both direct-and indirect-gap spacers. We show that the carrier confinement gives rise to a renormalization of the intensity of excitations through the band gap. The interband coupling decays exponentially with the distance between the ␦ layers and is strongly determined by the electron structure of the host. The estimates of the interlayer interaction parameters across Si, Ge, and GaAs spacers are presented. The combination of two mechanisms ͑confinement-mediated exchange and interband exchange͒ mainly determines the behavior of the interlayer coupling in the digital magnetic alloys with undoped spacer.