A writ of habeas corpus is a legal proceeding designed to bring a party before a court to test whether they are being held lawfully. A petition for writ of habeas corpus is a legal action that allows individuals to challenge their unlawful imprisonment or restraint.The writ of Habeas Corpus is the legal system's last line of defense against unlawful incarceration. A habeas corpus petition in California allows you to challenge your conviction or sentencing. You can file it only after exhausting all criminal appeals. A writ of habeas corpus is used to bring a prisoner or other detainee (e.g. Habeas corpus is a legal instrument that allows you to contest your incarceration, conviction, or sentencing conditions. The Writ of Habeas Corpus protects prison inmates from false imprisonment to ensure people are not thrown into jail unlawfully. Generally, an individual seeking to challenge his or her criminal conviction through a habeas petition must do so in a "timely fashion. Any prisoner, or another person acting on their behalf, may petition the court, or a judge, for a writ of habeas corpus.