Yes, select and then design the right ship. Certain ships have a built in lower 'profile' when it comes to NPC scans. The Krait(s) are low on this scale, the Python is much higher. As an analogy, the Python is a black BMW with personalised plates and tinted windows blaring the latest rap, whereas the Krait is a silver Jaguar. Who are the police going to run plates on first?
After choosing the right ship, design/engineer it to avoid scans. Speed, cool running, heat sinks, etc. are basic stealth/scan breaking tools. Whenever I have illicit cargo in my Python, I expect to get scanned so... drop out of SC already aligned with mail slot, boost, request docking, prepare to engage SR or drop a heat sink as soon as you get scan warning. Land quickly.
Yes, getting scanned will fail the mission.