Defendants who want to challenge the legality of their imprisonment -- or the conditions in which they are being imprisoned -- may seek help from a court by filing an application for what is known as a "writ of habeas corpus."
A writ of habeas corpus (literally to "produce the body") is a court order to a person (prison warden) or agency (institution) holding someone in custody to deliver the imprisoned individual to the court issuing the order. Many state constitutions provide for writs of habeas corpus, as does the U.S. Constitution, which specifically forbids the government from suspending writ proceedings except in extraordinary times -- such as war.
Known as "the Great Writ," habeas corpus gives citizens the power to get help from courts to keep government and any other institutions that may imprison people in check. In many countries, police and military personnel, for example, may take people and lock them up for months -- even years -- without charging them, and those imprisoned have no avenue, no legal channel, by which to protest or challenge the imprisonment.
The writ of habeas corpus gives jailed suspects the right to ask an appellate judge to set them free or order an end to improper jail conditions, and thereby ensures that people in this country will not be held for long times in prison in violation of their rights. Of course, the right to ask for relief is not the same as the right to get relief; courts are very stingy with their writs.
For clear and complete explanations of all aspects of criminal law and procedure, get The Criminal Law Handbook: Know Your Rights, Survive the System, Paul Bergman and Sara J. Berman (Nolo).