On a steam locomotive, the smokebox is the short tube, more or less the diameter of the boiler, that extends in front of it. The main purpose of the smokebox, which gives it its name, is to collect the smoke and other combustion gases that have passed through the numerous boiler tubes and boiler flues from the firebox, and eject them through the stack (archaically, the smokestack; in British parlance, the chimney).
To aid this flow, exhaust steam from the cylinders is ejected through an exhaust nozzle (UK: blastpipe) that points vertically upward in the smokebox, aimed at the exact center of the stack. This, coupled with a carefully-proportioned belled lower mouth of the stack, produces a partial vacuum, providing a forced draught of air and combustion gases through the firebox, tubes & flues, and out through the stack.
Also present in the smokebox is the superheater header, if the locomotive is superheated. A front-end throttle will also be mounted there. The steam pipes to the cylinders generally also pass through the smokebox; the higher temperatures inside the smokebox compared to the outside air mean the steam doesn't lose as much heat.
At the back of the firebox is the front tube sheet, that divides the water space from the smokebox. At the front of the smokebox, there is always a smokebox door. Different rail systems preferred different styles of smokebox door. British locomotives almost always had a smokebox door almost as large as the front of the smokebox; American locomotives often had a smaller door, generally round and in the middle, but sometimes offset, or squared-off. The method used for fastening the smokebox door securely varied also. The smokebox door was used for cleaning the smokebox of large cinders that passed through the tubes but would not go through the stack, and also for inspection.