Although it sounds like a gag to our post-modern ears, there really is a 1951 film called I Was a Communist for the FBI.
It’s a noir-ish melodrama, very much of its time, and one of those “based on a true story” endeavors, so viewer beware.
However, do note that commentators tend to dismiss the man who inspired the film, Matt Cvetic, as an emotionally unstable alcoholic — the very same libelous accusations thrown at Whittaker Chambers and Joe McCarthy himself, often by the same “educated” liberals who still spread the corny slander that J. Edgar Hoover wore women’s clothes.
(Speaking of Hoover: The Bureau was eager to distance itself from the film — until it was a hit.)