I agree that it is very nebulous whether or not the ultimate goals of the Foundation are "good" or "bad," but, unlike you, I'm reasonably certain that at the end of the day, the net impact of the Foundation is good, and not by any accident. I don't think the Foundation started its day by looking at the world and saying, "Let's contain all these anomalies." It saw the anomalies first, saw that, by and large, they wanted to fuck us up second, and then decided that they needed to be contained. That's a theme of the mission statement: the higher powers have it in for humanity.
Along the way, we have kidnapped and tortured for that end. And yeah, the Foundation probably has done it "for the greater good." Yes, if somebody in real life actually kidnapped and tortured and killed, and then they justified it as "for the greater good," then absolutely, they are probably pulling self-righteous bullshit out of their ass. They are probably not working for the greater good, because there's extreme doubt cast upon whatever cause that person might be working for. It's very indeterminate.
The Foundation is different, because this is fictionland. The Foundation has seen, with its own eyes, literally dozens of anomalies that would exterminate the human race given the chance. As opposed to Hitler, who did not see Jews ruining Europe because that did not actually happen, or Julius Caesar, who could not see any possible benefit from a Roman Empire because that's just guesswork, the Foundation has a very solid, non-ambiguous warrant for what it does. So it can subordinate stuff like "don't torture little girls."
And this is all wish-fulfillment. You will never find a person or organization that is consistently "saving the world" in real life.
I think the Foundation does have agency. There are specific bodies comprised of thinking people in charge of running it. They have a mission charter that they follow. That's moral agency, at least to me.
And yeah, the Foundation is only a net good. There's a bunch of fucked up stuff that it does ONLY for the sake of containment, NOT for any net good. This is a product of paranoia. But on balance, containment is the net good. This ties in to whether or not the people working for the Foundation are good. If you are the average Foundation personnel, you are containing something that is probably not even sapient, and is also probably trying to hurt a lot of people. You're probably not even complicit in the evil shit the Foundation does, because they keep that stuff classified and you'll never know about it. I'd say that you're a good person.