This study introduces an approach to analyze torsional vibration in non-circular nanowires within magnetic fields, considering various boundary conditions on an elastic foundation. Analytical formulas for natural angular frequencies are obtained using nonlocal strain gradient theory. The analysis covers three non-circular cross-sections, incorporating the warping effect. Elastic springs at the wire ends simulate support conditions, restricting rotation around the wire’s axis. The torsion function around the axis is represented by a Fourier series, discretized at the spring points and linked using the Stokes’ transform alongside the boundary values. This leads to an eigenvalue problem that includes higher-order material size parameters (strain gradient, nonlocal), spring parameters, and the warping function. The study’s novelty lies in effectively solving torsional vibration for non-circular sections, addressing warping function, elastic medium, and size effects under both deformable and non-deformable boundary conditions. The presented solution is capable of determining vibration frequencies for both rigid and deformable boundary conditions. This is accomplished by specifying the torsional spring stiffness values, thereby obviating the necessity for additional recalculations. In order to verify the obtained results and compare them with the existing literature, nanowires with free and clamped boundary conditions are solved numerically by changing the spring parameters in the eigenvalue problem. In the formulation of natural angular frequency; length scale parameters, warping, magnetic field, elastic medium effects are included. In addition, since the support conditions are modeled with elastic springs, the resulting formulas are quite general and can be used to solve different types of torsional vibration problems.