A scanning electron microscope (SEM) uses high-energy electrons to scan a specimen’s surface, creating a 3D image. In a conventional SEM, the specimen is placed in a vacuum. An electron beam passes through a couple of condenser lenses, which apply a magnetic field to narrow the beam and apertures (holes) to block stray electrons. The beam causes some electrons to be ejected, which can then be detected and amplified to produce an image of the sample surface.
Answered by Chi Wing Man.