Yolk–shell carbon spheres (YCS) have been widely used in many fields due to their abundant electron transport paths, high ion-accessibility and surface area as well as excellent mechanical properties. However, up to the present, the preparation of yolk–shell carbon spheres with tunable structures has always been a challenge. Herein, the direct conversion of solid resin spheres into YCS is achieved by a facile confined pyrolysis strategy. A silica shell with different degrees of openness is built on the surface of a solid resin sphere to form a confined nanospace, in which the volatile gases generated in the process of pyrolysis are deposited, forming a tunable yolk–shell structure. The results show that the YCS samples prepared in a relatively compact confined environment (YCS-C) have a thinner shell, higher surface area and richer porous structure. As electrode materials for supercapacitors, YCS-C show an excellent specific capacitance of 330 F g−1 at 0.5 A g−1 and outstanding stability with 88.5% initial capacity retention after 10 000 cyclic tests, making them promising candidates for high-performance energy storage devices.