UV bursts are transients in the solar atmosphere with an increased impulsive emission in the extreme UV lasting for one to several tens of minutes. They often show spectral profiles indicative of a bi-directional outflow in response to magnetic reconnection. To understand UV bursts, we study how motions of magnetic elements at the surface can drive the self-consistent formation of a current sheet resulting in plasmoid-mediated reconnection. In particular, we want to study the role of the height of the reconnection in the atmosphere. We conducted numerical experiments solving the 2D MHD equations from the solar surface to the upper atmosphere. Motivated by observations, we drove a small magnetic patch embedded in a larger system of magnetic field of opposite polarity. This configuration creates an X-type neutral point in the initial potential field. The models are characterized by the plasma-beta at the height of this X point. The driving at the surface stretches the X-point into a current sheet, where plasmoids appear, and a bi-directional jet forms. This is consistent with what is expected for UV bursts or explosive events, and we provide a self-consistent model of the formation of the reconnection region in such events. The gravitational stratification gives an explanation for why explosive events are restricted to a temperature range around a few 0.1 MK, and the presence of plasmoids in the reconnection process provides an understanding of the observed variability during the transient events on a timescale of minutes. Our numerical experiments provide a comprehensive understanding of UV bursts and explosive events, in particular of how the atmospheric response changes if the reconnection happens at different plasma-beta, that is, at different heights in the atmosphere. This analysis also gives new insight into how UV bursts might be related to the photospheric Ellerman bombs.