When it is necessary to have a person imprisoned in the state prison brought before any court to be tried for a felony, or for an examination before a grand jury or magistrate preliminary to such trial, or for the purpose of hearing a motion or other proceeding, to vacate a judgment, an order for the prisoner’s temporary removal from said prison, and for the prisoner’s production before such court, grand jury or magistrate, must be made by the superior court of the county in which said action, motion, or examination is pending or by a judge thereof; such order shall be made only upon the affidavit of the district attorney or defense attorney, stating the purpose for which said person is to be brought before the court, grand jury or magistrate or upon the court’s own motion. The order shall be executed by the sheriff of the county in which it shall be made, whose duty it shall be to bring the prisoner before the proper court, grand jury or magistrate, to safely keep the prisoner, and when the prisoner’s presence is no longer required to return the prisoner to the prison from whence the prisoner was taken; the expense of executing such order shall be a proper charge against, and shall be paid by, the county in which the order shall be made.
Such order shall recite the purposes for which said person is to be brought before the court, grand jury or magistrate, and shall be signed by the judge making the order and sealed with the seal of the court. The order must be to the following effect:
County of ____ (as the case may be).
The people of the State of California to the warden of ____:
An order having been made this day by me, that A.B. be produced in the ____ court (or before the grand jury, as the case may be) to be prosecuted or examined for the crime of ____, a felony (or to have said motion heard), you are commanded to deliver the prisoner into the custody of ____ for the purpose of (recite purposes).
Dated this ____ day of ____, 19__.
When a prisoner is removed from a state prison under this section the prisoner shall remain in the constructive custody of the warden thereof. During the prisoner’s absence from the prison, the prisoner may be ordered to appear in other felony proceedings as a defendant or witness in the courts of the county from which the original order directing removal issued. A copy of the written order directing the prisoner to appear before any such court shall be forwarded by the district attorney to the warden of the prison having protective custody of the prisoner.