The bacterium Helicobacter pylori causes ulcers in the stomach of humans by invading mucus layers protecting epithelial cells. It does so by chemically changing the rheological properties of the mucus from a high-viscosity gel to a low-viscosity solution in which it may self-propel. We develop a two-fluid model for this process of swimming under self-generated confinement. We solve exactly for the flow and the locomotion speed of a spherical swimmer located in a spherically symmetric system of two Newtonian fluids whose boundary moves with the swimmer. We also treat separately the special case of an immobile outer fluid. In all cases, we characterise the flow fields, their spatial decay, and the impact of both the viscosity ratio and the degree of confinement on the locomotion speed of the model swimmer. The spatial decay of the flow retains the same power-law decay as for locomotion in a single fluid but with a decreased magnitude. Independently of the assumption chosen to characterise the impact of confinement on the actuation applied by the swimmer, its locomotion speed always decreases with an increase in the degree of confinement. Our modelling results suggest that a low-viscosity region of at least six times the effective swimmer size is required to lead to swimming with speeds similar to locomotion in an infinite fluid, corresponding to a region of size above $approx 25~mu$m for Helicobacter pylori.