Habeas corpus is a remedy of last resort for prisoners. Used by state and federal inmates alike, it is often the final opportunity to challenge the legality of a criminal conviction or sentence.