Forward contamination is prevented by sterilizing rovers sent to sensitive areas of the Solar System.
Backward contamination would be prevented by containment or quarantine; however, there have been no sample returns thought to have any possibility of a back contamination risk since the Apollo missions.