  The two-dimensional electron gas found at the surface of SrTiO$_3$ and
related interfaces has attracted significant attention as a promising basis for
oxide electronics. In order to utilize its full potential, the response of this
2DEG to structural changes and surface modification must be understood in
detail. Here, we present a study of the detailed electronic structure evolution
of the 2DEG as a function of sample temperature and surface step density. By
comparing our experimental results with \textit{ab initio} calculations, we
found that a SrO-rich surface layer is a prerequisite for electronic
confinement. We also show that local structure relaxations cause a
metal-insulator transition of the system around 135~K. Our study presents a new
and simple way of tuning the 2DEG via surface vicinality and identifies how the
operation of prospective devices will respond to changes in temperature.
