One should maintain a strong sense of self - discipline. If you find yourself having any improper thoughts about your best friend's wife, immediately distance yourself. Also, focus on building healthy relationships outside of this potentially dangerous situation. For example, engage more in group activities with other friends or focus on your own personal growth and hobbies. This way, you can keep your mind occupied with positive things and avoid any situations that could lead to such inappropriate involvements.
Simple. Just respect boundaries. Always remember that your best friend's wife is off - limits. Don't let any inappropriate feelings develop in the first place.