The penta-hybrid nanofluid is a nanofluid that contains five different types of nanoparticles. It can achieve higher heat transfer rates than conventional hybrid nanofluids due to the synergistic effects of the nanoparticles. It also has more diverse physical and thermal properties, which make it more adaptable for various applications. Therefore, this research examines the influence of localized magnetic fields on the vortex dynamics in a penta-hybrid nanofluidic flow in a vertical cavity with an aspect ratio of 1:10, driven by a top and bottom lid moving in the opposite direction. The stream-vorticity formulation is used to solve the dimensionless governing partial differential equation. A confined magnetic field in the form of horizontal and vertical strips has been applied instead of a uniform magnetic field throughout the flow domain, which is more realistic. Moreover, MATLAB codes developed by the authors are used to investigate how these parameters affect the flow and thermal properties of the nanofluids. The results suggest that magnetic fields have an impact on how stress, flow patterns, and temperature are distributed. Moreover, the presence of a magnetic field influences the spacing of isotherms, indicating a more even temperature distribution. It has also been observed that stress distribution is affected by the magnetic field, with higher stress levels near walls and regions with velocity-induced stress. However, in certain areas, the magnetic field can decrease shear stress depending on its strength and orientation. These study findings have implications for designing and operating nanofluidic devices. For instance, utilizing a magnetic field can help regulate flow patterns, temperature distribution, and stress distribution within nanofluidic channels. This capability could prove beneficial for a range of applications, such as cell separation, drug delivery, and nanofluidic heat exchange systems.