The engineering of electron wave functions in reduced dimensions has allowed researchers to explore and visualize fundamental aspects of quantum mechanics and has also led to new ideas for advanced materials and devices. The scanning tunnelling microscope, in particular, has been used to create two-dimensional structures such as quantum corrals by moving individual atoms on metal surfaces and then probing the quasi two-dimensional surface state electron gases confined therein. However, this serial approach is time-consuming and not suited to producing ensembles of nanostructures for the control of electrons. Here we introduce a novel bottom-up method for the fabrication of nanoscale confinement structures on the Ag(111) surface. Scanning tunnelling spectroscopy data show that self-assembled molecular gratings act as one-dimensional resonators, and allow us to tune the characteristics of quantum-well states. We also demonstrate zero-dimensional confinement in quantum corrals down to 2×5nm in size by positioning single Fe atoms, which act as additional electron reflectors, in the molecular gratings.