If a person is required to give security to keep the peace or for his good behavior, the court or justice may order him to pay the expenses of prosecution, or any part thereof, and that he shall stand committed until they are paid or he is otherwise legally discharged.
Mass. Gen. Laws ch. 275, § 7