At any time before final judgment against them, the bail may surrender the defendant in their exoneration, or he may surrender himself to the sheriff of the county where he was arrested, in the following manner:
(1) A certified copy of the undertaking of the bail shall be delivered to the sheriff, who shall detain the defendant in his custody thereon, as upon an order of arrest, and acknowledge the surrender by a certificate in writing.
(2) Upon the production of a copy of the undertaking and sheriff's certificate, the court or judge may, upon a notice to the plaintiff of ten days, with a copy of the certificate, order that the bail be exonerated, and on filing the order and papers used on said application they shall be exonerated accordingly. But this section does not apply to an arrest in an action to recover the possession of personal property unjustly detained, so as to discharge the bail from an undertaking given to the effect provided by law to be given by defendant for the retention of property, under the Article entitled Claim and Delivery. (C.C.P., s. 158; Code, s. 300; Rev., s. 752; C.S., s. 792.)