Except as otherwise provided in this section, moneys deposited as bail are the property of the defendant, whether deposited by the defendant or by a third person on the defendant's behalf. If bail moneys are deposited by a third person, the person must be notified at the time of deposit that the moneys may be paid to the defendant upon final disposition of the case or applied to any fine, cost, or restitution imposed on the defendant. The person may direct, subject to further order of the judge, that the deposited moneys be released to that person upon final disposition of the case. When moneys are accepted by the court as bail, the judge shall order that the moneys received be deposited with the clerk of court. The clerk shall retain the moneys until the final order of the court disposing of the case. Upon release of the moneys held by the clerk, the moneys must be paid to the defendant or pursuant to the defendant's written direction or, unless otherwise ordered by the judge, as directed by a person who deposited moneys on behalf of the defendant. In the case of a conviction, the judge may order the moneys to be applied to any fine, cost, or restitution imposed on the defendant. The balance of the deposit, if any, must be paid to the defendant. Moneys deposited with the court or clerk of court as bail are exempt from garnishment, attachment, or execution.
N.D.C.C. § 29-08-28