Context. Water fountain stars represent a stage between the asymptotic giant branch (AGB) and planetary nebulae phases, when the mass loss changes from spherical to bipolar. These types of evolved objects are characterized by high-velocity jets in the 22 GHz water maser emission. Aims. The objective of this work is to detect and study in detail the circumstellar gas in which the bipolar outflows are emerging. The detection and study of thermal lines may help in understanding the nature and physics of the envelopes in which the jets are developing. Methods. We surveyed the CO and 13 CO line emission towards a sample of ten water fountain stars through observing the J = 1 → 0 and 2 → 1 lines of CO and 13 CO, using the 30 m IRAM radio-telescope at Pico Veleta. All the water fountains visible from the observatory were surveyed. Results. Most of the line emission arises from foreground or background Galactic clouds, and we had to thoroughly analyse the spectra to unveil the velocity components related to the stars. In two sources, IRAS 18460-0151 and IRAS 18596+0315, we identified wide velocity components with a width of 35−40 km s −1 that are centred at the stellar velocities. These wide components can be associated with the former AGB envelope of the progenitor star. A third case, IRAS 18286-0959, is reported as tentative; in this case a pair of narrow velocity components, symmetrically located with respect to the stellar velocity, have been discovered. We also modelled the line emission using an LVG code and derived some global physical parameters, which allowed us to discuss the possible origin of this gas in relation to the known bipolar outflows. For IRAS 18460-0151 and IRAS 18596+0315, we derived molecular masses close to 0.2 M , mean densities of 10 4 cm −3 , and mass-loss rates of 10 −4 M yr −1 . The kinetic temperatures are rather low, between 10 and 50 K in both cases, which suggests that the CO emission is arising from the outer and cooler regions of the envelopes. No fitting was possible for IRAS 18286-0959, because line contamination can not be discarded in this case. Conclusions. The molecular masses, mean densities, and mass-loss rates estimated for the circumstellar material associated with IRAS 18460-0151 and IRAS 18596+0315 confirm that these sources are at the end of the AGB or the beginning of the post-AGB evolutionary stages. The computed mass-loss rates are among the highest ones possible according to current evolutionary models, which leads us to propose that the progenitors of these water fountains had masses in the range from 4 to 8 M . We speculate that CO emission is detected in water fountains as a result of a CO abundance enhancement caused by current episodes of low-collimation mass-loss.