This paper deals with nonlocal divergence and flutter instability analysis of carbon nanotubes (CNTs) conveying fluid embedded in an elastic foundation under magnetic field. Nonlocal constitutive equations of Eringen and Euler–Bernoulli beam theory are used in the formulations. Also, the foundation is described by the Winkler and Pasternak models. The governing equation of motion and boundary conditions are derived using extended Hamilton’s variational principle. The extended Galerkin’s approach is adopted to reduce the partial differential equation governing the dynamics of the CNTs to a system of coupled ordinary differential equations. In the present study, four different boundary conditions are considered, namely the pined–pined (P–P), clamped–pined (C–P), clamped–clamped (C–C) and clamped–free (C–F). A detailed parametric study is conducted to elucidate the effects of the nonlocal effect, longitudinal magnetic field, elastic Winkler and Pasternak foundations and geometrically boundary conditions on the instability characteristic of CNTs. It was observed that the only instability type for the investigated CNT with clamped–free boundary condition (cantilever) is flutter, while CNT conveying fluid with both ends supported loses its stability by divergence first and then by flutter with increase in fluid velocity. It was also found that the magnetic field and the Winkler and Pasternak foundations increase the stiffness of the system. Therefore, flutter instability region is enlarged significantly due to the existence of springs, shear foundations and magnetic field. Also, results show that the nonlocal parameter has a prominent effect on the stability behavior of CNTs, in which increasing nonlocal parameter results in the decrease in stability region. Furthermore, it was shown that the stability behavior of CNT is strongly affected by different boundary conditions. Finally, the validity of the present analysis is confirmed by comparing the results with those obtained from the literature.