When I'm in the code hacking minigame, I always see "3 attempts remaining" at the bottom of the screen. I'm not sure how this is used though.
In my experience, if I run my cursor into a red section, it removes one piece I've already hacked. If I do that when I don't have any pieces hacked, I get locked out of the system, and can't attempt a hack again. So where does the 3 attempts remaining come in?