Habeas corpus is a writ used to bring a person before the court, usually to make sure the person's detention or imprisonment is not illegal, or that the arrest wasn't illegal, although it can be used for review of the process, bail, or to question jurisdiction.
The writ would be filed in court by the person objecting to the detention or imprisonment, generally due to a legal or factual error. Habeas relief is not granted unless the petitioner can show it resulted in an actual prejudice that affected the original judgment.
The writ is handwritten and signed by the petitioner, under penalty of perjury. All grounds for habeas relief should be included. Additional pages are not permitted, however. There is a minor fee to file the writ, and there are generally costs involved in acquiring transcripts, counsel, etc. It would be wise to have your incarcerated friend consult with an attorney.