This work introduces a new electron gun geometry capable of robust functioning in the presence of a high strength external magnetic field for axisymmetric magnetic resonance imaging (MRI)-linac configurations. This allows an inline MRI-linac to operate without the need to isolate the linear accelerator (linac) using a magnetic shield. This MRI-linac integration approach not only leaves the magnet homogeneity unchanged but also provides the linac flexibility to move along the magnet axis of symmetry if the source to target distance needs to be adjusted. Simple electron gun geometry modifications of a Varian 600 C electron gun are considered and solved in the presence of an external magnetic field in order to determine a set of design principles for the new geometry. Based on these results, a new gun geometry is proposed and optimized in the fringe field of a 0.5 T open bore MRI magnet (GE Signa SP). A computer model for the 6 MeV Varian 600 C linac is used to determine the capture efficiency of the new electron gun-linac system in the presence of the fringe field of the same MRI scanner. The behavior of the new electron gun plus the linac system is also studied in the fringe fields of two other magnets, a 1.0 T prototype open bore magnet and a 1.5 T GE Conquest scanner. Simple geometrical modifications of the original electron gun geometry do not provide feasible solutions. However, these tests show that a smaller transverse cathode diameter with a flat surface and a slightly larger anode diameter could alleviate the current loss due to beam interactions with the anode in the presence of magnetic fields. Based on these findings, an initial geometry resembling a parallel plate capacitor with a hole in the anode is proposed. The optimization procedure finds a cathode-anode distance of 5 mm, a focusing electrode angle of 5°, and an anode drift tube length of 17.1 mm. Also, the linac can be displaced with ± 15 cm along the axis of the 0.5 T magnet without capture efficiency reduction below the experimental value in zero field. In this range of linac displacements, the electron beam generated by the new gun geometry is more effectively injected into the linac in the presence of an external magnetic field, resulting in approximately 20% increase of the target current compared to the original gun geometry behavior at zero field. The new gun geometry can generate and accelerate electron beams in external magnetic fields without current loss for fields higher than 0.11 T. The new electron-gun geometry is robust enough to function in the fringe fields of the other two magnets with a target current loss of no more than 16% with respect to the current obtained with no external magnetic fields. In this work, a specially designed electron gun was presented which can operate in the presence of axisymmetric strong magnetic fringe fields of MRI magnets. Computer simulations show that the electron gun can produce high quality beams which can be injected into a straight through linac such as Varian 600 C and accelerated with more efficiency in the presence of the external magnetic fields. Also, the new configuration allows linac displacements along the magnet axis in a range equal to the diameter of the imaging spherical volume of the magnet under consideration. The new electron gun-linac system can function in the fringe field of a MRI magnet if the field strength at the cathode position is higher than 0.11 T. The capture efficiency of the linac depends on the magnetic field strength and the field gradient. The higher the gradient the better the capture efficiency. The capture efficiency does not degrade more than 16%.