Abstract: We  study the confinement of Dirac fermions in graphene and in carbon nanotubes by an external magnetic field, mechanical deformations or inhomogeneities in the substrate. By applying variational principles to the square of the Dirac operator, we obtain sufficient and necessary conditions for confinement of the quasi-particles. The rigorous theoretical results are illustrated on the realistic examples of the three classes of traps.