Broadly speaking, it's the job of the executive government to prevent this, of which CIA and NSA are merely tools. However, it turns out that, in America, you can literally buy the executive wholesale as a foreign actor with enough resources and determination.
And we can't even say that this was a surprise. Federalist Papers No 22:
"Evils of this description ought not to be regarded as imaginary. One of the weak sides of republics, among their numerous advantages, is that they afford too easy an inlet to foreign corruption. An hereditary monarch, though often disposed to sacrifice his subjects to his ambition, has so great a personal interest in the government and in the external glory of the nation, that it is not easy for a foreign power to give him an equivalent for what he would sacrifice by treachery to the state. The world has accordingly been witness to few examples of this species of royal prostitution, though there have been abundant specimens of every other kind.
In republics, persons elevated from the mass of the community, by the suffrages of their fellow-citizens, to stations of great pre-eminence and power, may find compensations for betraying their trust, which, to any but minds animated and guided by superior virtue, may appear to exceed the proportion of interest they have in the common stock, and to overbalance the obligations of duty. Hence it is that history furnishes us with so many mortifying examples of the prevalency of foreign corruption in republican governments."
And we can't even say that this was a surprise. Federalist Papers No 22:
"Evils of this description ought not to be regarded as imaginary. One of the weak sides of republics, among their numerous advantages, is that they afford too easy an inlet to foreign corruption. An hereditary monarch, though often disposed to sacrifice his subjects to his ambition, has so great a personal interest in the government and in the external glory of the nation, that it is not easy for a foreign power to give him an equivalent for what he would sacrifice by treachery to the state. The world has accordingly been witness to few examples of this species of royal prostitution, though there have been abundant specimens of every other kind.
In republics, persons elevated from the mass of the community, by the suffrages of their fellow-citizens, to stations of great pre-eminence and power, may find compensations for betraying their trust, which, to any but minds animated and guided by superior virtue, may appear to exceed the proportion of interest they have in the common stock, and to overbalance the obligations of duty. Hence it is that history furnishes us with so many mortifying examples of the prevalency of foreign corruption in republican governments."