Quite a few of you are saying "Depends" so allow me to expend on my original point:
1. Lets assume its a companion and they end up either joining the big bad or selling you out or had been a double agent this whole time, they may even be your LI so you can factor that in if you wish.
2. An ally sells you out to the benefit of his/her own people/organization/etc, it might be because he/she is a dirty good for nothing or it might be that he/she has lost faith in your ability to win, it might even be that they are being coerced.
3. Random quest dude/tte gives you a task, when you get to location of said task you are ambushed, turns out Random quest dude/tte set you up, now he/she might have a very good sob story lined up, such as they threatened his life/family/pet Nug, remember he/she might be lying.
Now what would you do:
1. Kill/Butcher/Slay the would be traitor/s (The most efficient route Imo)
2. Imprison them (though for the life of me i cant figure why you would want to waste resources on traitorous scum).
3. Exile/Banish them ( That may end-up biting your in the ass)
4. Forgive them ( The most likely option that might bite you in the ass, hope your wearing reinforced loincloth)
Go! 