Polymeric nitrogen as a new class of high energy density materials has promising applications. We develop a new scheme of crystal structure searching in a confined space using external confining potentials fitted from firstprinciples calculations. As a showcase, this method is employed to systematically explore novel polymeric nitrogen structures confined in single-walled carbon nanotubes. Several quasi-one-dimensional single-bonded polymeric nitrogen structures are realized, two of them are composed of nanotubes instead of chains. These new polymeric nitrogen phases are mechanically stable at ambient pressure and temperature according to phonon calculations and ab initio molecular dynamics simulations. It is revealed that the stabilization of zigzag and armchair chains confined in carbon nanotubes are mostly attributed to the charge transfer from carbon to nitrogen. However, for the novel nitrogen nanotube systems, electrons overlapping in the middle space provide strong Coulomb repulsive forces, which not only induce charge transfer from the middle to the sides but also stabilize the polymeric nitrogen. Our work provides a new strategy for designing novel high-energy-density polymeric nitrogen materials, as well as other new materials with the help of confined space inside porous systems, such as nanotubes, covalent organic frameworks, and zeolites.