Observations show that the Sun sheds mass through twisted magnetic flux configurations, like Coronal Mass Ejections (CMEs). Conventionally, CMEs are modeled by adopting a given distribution of magnetic flux at the solar surface and letting it evolve by shearing and twisting the magnetic field at its footpoints at the surface. Of course, ultimately such velocity and magnetic field
patterns must come from a realistic simulation of the Sun's convection zone, where the field is generated by dynamo action. Therefore a unified treatment of convection zone and CMEs is needed. We combine a convectively driven dynamo with a polytropic layer that extends to 1.6 solar radii. The temperature increases in this region to about 8 times the value at the surface, corresponding to about 1.2 times the value at the bottom of the spherical shell. We associate this region with the solar corona. Magnetic fields are found to emerge at the surface and are ejected to the coronal part of the domain. These ejections occur in irregular intervals and are weaker than in earlier work. We tentatively associate these events with coronal mass ejections on the Sun. We find a solar-like differential rotation with radial contours of constant rotation rate, together with a solar-like meridional circulation and a near-surface shear layer. This spoke-like rotation profile is caused by a non-zero latitudinal entropy gradient which violates the Taylor-Proudman balance via the baroclinic term. The lower density stratification compared with the Sun leads to an equatorward return flow above the surface. The mean magnetic field is in most of the cases oscillatory with equatorward migration in one case. In other cases the equatorward migration is overlaid by stationary or even poleward migrating mean fields.