Laser-cooled atoms that are trapped and optically interfaced with light in nanophotonic waveguides are a powerful platform for fundamental research in quantum optics as well as for applications in quantum communication and quantum-information processing. Ever since the first realization of such a hybrid quantum-nanophotonic system about a decade ago, heating rates of the atomic motion observed in various experimental settings have typically been exceeding those in comparable free-space optical microtraps by about three orders of magnitude. This excessive heating is a roadblock for the implementation of certain protocols and devices. Still, its origin has so far remained elusive and, at the typical atom-surface separations of less than an optical wavelength encountered in nanophotonic traps, numerous effects may potentially contribute to atom heating. Here, we theoretically describe the effect of mechanical vibrations of waveguides on guided light fields and provide a general theory of particle-phonon interaction in nanophotonic traps. We test our theory by applying it to the case of laser-cooled cesium atoms in nanofiber-based two-color optical traps. We find excellent quantitative agreement between the predicted heating rates and experimentally measured values. Our theory predicts that, in this setting, the dominant heating process stems from the optomechanical coupling of the optically trapped atoms to the continuum of thermally occupied flexural mechanical modes of the waveguide structure. Surprisingly, the effect of the high-Q mechanical resonances which have previously been observed in this system can be neglected, even if they coincide with the trap frequencies. Beyond unraveling the long-standing riddle of excessive heating in nanofiber-based atom traps, we also study the dependence of the heating rates on the relevant system parameters and find a strong R −5/2 scaling with the inverse waveguide radius. Our findings allow us to propose several strategies for minimizing the heating which also provide guidelines for the design of next-generation nanophotonic cold-atom systems. Finally, given that the predicted heating rate is proportional to the mass of the trapped particle, our findings are also highly relevant for optomechanics experiments with dielectric nanoparticles that are optically trapped close to nanophotonic waveguides.We discuss additional heating mechanisms for the motion of atoms in nanofiber-based optical dipole traps. In particular, we provide estimates for the setup described in [1] and [2], which is the setup the case study in our manuscript refers to.