You can add yourself to the the Undead faction, and guards will not attack you. So long as the faction you have doesn't have a negative affiliation with someone in specific, you'll be fine. This is because the Player character as an aggression of 1. For instance, adding yourself to the non-playable Stormcloak faction will make every single Imperial guard hostile to you. This is because the Stormcloak faction actually has a negative number against Imperial Legion.(I think it's negative 50, could actually be -100...)
Bandits & Forsworn faction do not have a negative relation with guards. What makes them "hostile" is their aggression being set to 3. The faction just keeps these very aggressives from attacking each other.
In strict game-mechanics talk, of course.