This chapter shall not authorize the taking of a person by writ of habeas corpus out of the custody of the United States marshal, or his deputy, who holds him by legal and sufficient process issued by any court or magistrate of competent jurisdiction; but this section shall not affect the authority of the supreme judicial court or of its justices, in accordance with the provisions of the constitution of the United States and of the commonwealth, to investigate and determine the validity and legal effect of any process which may be relied on to defeat the writ, or any other matter properly arising.
Mass. Gen. Laws ch. 248, § 34