Why does molecules in MD trajectory go out of the pbc box in VMD / pymol?

I have done an MD simulation of a few oligopeptides and obtained the trajectory. When I visualize it using VMD/ Pymol molecules move out of the PBC box.

Why does it happen ?
How can I keep the molecules within the box?

A periodic system is infinite; there is no such thing as “outside” of a box, nor should you try to constrain your molecules to remain within it. You can recenter on some useful/convenient reference with gmx trjconv and see how other molecules in the system move relative to it, but otherwise there are no tricks that should be played.