We study analytically the influence of lateral confinement on the penetration depth of a sphere into a granular medium by impact. The granular medium is contained in a cylindrical tank of diameter $D$ and a sphere of diameter $d$ plunges along its axis. The presence of side walls, parametrized by the distance $D-d$ between the walls and the sphere, influences the penetration depth. Here, we deploy a continuous analytical model to account for the presence of side walls. After solving and calibrating this model for an infinite medium ($D/d\rightarrow \infty$), we show that it is possible to extend this model without any additional parameters to account for lateral confinement. The influence of side walls is modelled by an exponential effect, which modifies the sphere's penetration dynamics. The solution of the model is shown to be in agreement with experimental results.