At any time before failure to comply with the undertaking, the bail may surrender the defendant in their exoneration, or the defendant may surrender to a peace officer of the court where the action is pending.