We undertake a first-principles analysis of the thermodynamics of a small body near a black hole horizon. In particular, we study the paradigmatic system of a quantum ideal gas in a small box hovering over the Schwarzschild horizon. We describe the gas in terms of free quantum fields, bosonic and fermionic, massive and massless. We identify thermodynamic properties through the microcanonical distribution. We first analyse the more general case of a box in Rindler spacetime, and then specialize to the black hole case. The physics depends strongly on the distance of the box from the horizon, which we treat as a macroscopic thermodynamic variable. We find that the effective dimension of the system transitions from three-dimensional to two-dimensional as we approach the horizon, that Bekenstein's bound fails when the box is adiabatically lowered towards the black hole, and that the pressure is highly anisotropic. The pressure difference between the upper and lower wall leads to an effective force that must be added to the gravitational acceleration. We also show that the approximation of quantum fields propagating on a fixed background for matter breaks down when the system is brought to microscopic distances from the horizon, in which case backreaction effects must be included.