(a) The officer granting the writ may previously require bond, with surety, in sufficient penalty, payable to the state or to the person against whom the writ is directed, conditioned that the person detained shall not escape by the way, and for the payment of such costs and charges as may be awarded against him or her.
(b) The bond shall be filed with the other proceedings in the court and may be sued on by the state for the benefit of any person injured by the breach of it.