Eugene Debs, a Socialist leader in the early 20th century, ran for President five times. His fifth and highest vote count came in the 1920 Presidential election, in which he was running while in Federal prison for sedition. He received about 3.4% of the vote at the time (which included women for the first time since the Nineteenth Amendment was passed in 1920 as well). Not naming names, but yes, it’s possible to run for President while in prison, though results may vary.
I love me some Debs. Dude was righteous as hell, and would have certainly received my vote had I been alive. Check out some of his quotes: https://en.m.wikiquote.org/wiki/Eugene_V._Debs