Consider two different spies:
Betrayer: Alice is in a position of trust among the enemy. She is then recruited to work against those who trust her.
Mole: Bob is not yet in a position of trust among the enemy, but he is recruited to gain their trust, with a view to eventually working against them.
I assume that the enemy is morally in the wrong, and that just allows our side to work to undermine the enemy. But I think there is a moral problem with moles that betrayers don’t have which we can get at by considering a parallel distinction between two cases of people who promise the wrong thing:
Carl realizes that a promise he made is one that it is morally wrong to keep, and hence he does not keep it.
Danielle makes a promise knowing that it would be morally wrong to keep it, without intending to keep it.
Carl is acting well. He shouldn’t have made the promise, but since a promise of immoral activity is null and void, he rightly refuses to keep the promise. Carl may or may not have been culpable for making the promise, but in neither case should he keep it.
Danielle acts badly. She is insincerely gaining the trust of people. Her action is bad even if she knows that the promise is null and void.
Alice the Betrayer is like Carl. Alice attained a position of trust in a morally corrupt hierarchy. She shouldn’t have signed up for that. But whether she is culpable for that or not, it is right for her to go against that trust. Unjust commitments are null and void. While her fellows may in fact trust her to keep working on their side, they shouldn’t.
However, Bob is working to gain a trust he intends not to keep. This seems morally bad, even though it is a trust that he shouldn’t keep.