A particle code has been developed to study the distribution and acceleration of electrons in electric discharges in air. The code can follow the evolution of a discharge from the initial stage of a single free electron in a background electric field to the formation of an electron avalanche and its transition into a streamer. The code is in 2D axi-symmetric coordinates, allowing quasi 3D simulations during the initial stages of streamer formation. This is important for realistic simulations of problems where space charge fields are essential such as in streamer formation. The charged particles are followed in a Cartesian mesh and the electric field is updated with Poisson's equation from the charged particle densities. Collisional processes between electrons and air molecules are simulated with a Monte Carlo technique, according to cross section probabilities. The code also includes photoionisation processes of air molecules by photons emitted by excited constituents. The paper describes the code and presents some results of streamer development at 70km altitude in the mesosphere where electrical discharges (sprites) are generated above severe thunderstorms and at ∼10km relevant for lightning and thundercloud electrification. The code is used to study acceleration of thermal seed electrons in streamers and to understand the conditions under which electrons may reach energies in the runaway regime. This is the first study in air, with a particle model with realistic spatial dependencies of the electrostatic field. It is shown that at 1atm pressure the electric field must exceed ∼7.5 times the breakdown field to observe runaway electrons in a constant electric field. This value is close to the field where the electric force on an electron equals the maximum frictional force on an electron - found at ∼100eV. It is also found that this value is reached in a negative streamer tip at 10km altitude when the background electric field equals ∼3 times the breakdown field. At higher altitudes, the background electric field must be relatively larger to create a similar field in a streamer tip because of increased influence of photoionisation. It is shown that the role of photoionization increases with altitude and the effect is to decrease the space charge fields and increase the streamer propagation velocity. Finally, effects of electrons in the runaway regime on negative streamer dynamics are presented. It is shown the energetic electrons create enhanced ionization in front of negative streamers. The simulations suggest that the thermal runaway mechanism may operate at lower altitudes and be associated with lightning and thundercloud electrification while the mechanism is unlikely to be important in sprite generation at higher altitudes in the mesosphere.