Pits have been observed on many cometary nuclei mapped by spacecraft. It has been argued that cometary pits are a signature of endogenic activity, rather than impact craters such as those on planetary and asteroid surfaces. Impact experiments and models cannot reproduce the shapes of most of the observed cometary pits, and the predicted collision rates imply that few of the pits are related to impacts. Alternative mechanisms like explosive activity have been suggested, but the driving process remains unknown. Here we report that pits on comet 67P/Churyumov-Gerasimenko are active, and probably created by a sinkhole process, possibly accompanied by outbursts. We argue that after formation, pits expand slowly in diameter, owing to sublimation-driven retreat of the walls. Therefore, pits characterize how eroded the surface is: a fresh cometary surface will have a ragged structure with many pits, while an evolved surface will look smoother. The size and spatial distribution of pits imply that large heterogeneities exist in the physical, structural or compositional properties of the first few hundred metres below the current nucleus surface.