He is an old man and tells Puss his name is Andy Beanstalk, but his friends call him Jack, thus his name, Jack Andy Beanstalk, is a parody of Jack and the Beanstalk, whom (it is supposed, by his words) he is the character from.
All that is known about his early life is what he tells Puss, that he is the Jack that gained the magic beans, went up the beanstalk and killed the giant, yet still retained some magic beans on him. It wasn't his family cow he traded for the beans, though, but rather "some other family's family cow" and this crime of theft got him eight to ten years sentence in the San Ricardo prison.
As it is presumed he was a youth at this time, Jack has been in prison well over his sentencing, giving his old age, but he has either not noticed this or has little control over his own fate. He doesn't realize he can slip his hands free of his shackles and regularly slips them out to gesture, but then will sets them right back in.
His cell mate history is probably varied but unknown except that he counts Humpty Alexander Dumpty as his least favorite cell mate. Much as he did with Puss, he told the story of how he ended up in jail to Humpty and then the egg at some point stole his magic beans off of him, perhaps during one of his many fits of falling asleep.
It is presumed he was awake and aware of the theft at some point before Humpty's escape, though, as he tells Puss he tried to tell Humpty not to take the Golden Goose as it would cause trouble when it's momma the "Great Terror" came after it.
In the same way he talked much of what he had done to Humpty, the egg told him enough of his plans of revenge that Jack knew getting back at a cat named Puss in Boots was what the egg was after. Once Puss is thrown in jail, Jack thus concludes that "the egg got what he wanted". He proceeds to tell Puss the same story and also of what Humpty did, thus enlightening the cat to the plight of San Ricardo and undoing Jack's own folly in telling Humpty enough to spur majority of the bad events of the movie, though unintentionally.
The two, Jack and Puss, are freed when Kitty Softpaws knocks out a guard. She apologizes to Puss for betraying him, and Jack cluelessly states that he forgives her before rushing off to freedom from the cell.