A non-destructive sorting method to separate single-walled carbon nanotubes (SWNTs) by diameter was recently proposed. By this method, SWNTs are suspended in water by surfactant encapsulation and the separation is carried out by ultracentrifugation in a density gradient. SWNTs of different diameters are distributed according to their densities along the centrifuge tube. A mixture of two anionic surfactants, namely sodium dodecylsulfate (SDS) and sodium cholate (SC), presented the best performance in discriminating nanotubes by diameter. Unexpectedly, small diameter nanotubes are found at the low density part of the centrifuge tube. We present molecular dynamics studies of the water-surfactant-SWNT system to investigate the role of surfactants in the sorting process. We found that surfactants can actually be attracted towards the interior of the nanotube cage, depending on the relationship between the surfactant radius of gyration and the nanotube diameter. The dynamics at room temperature showed that, as the amphiphile moves to the hollow cage, water molecules are dragged together, thereby promoting the nanotube filling. The resulting densities of filled SWNT are in agreement with measured densities.