The plaintiff at the time of commencing an action of forcible entry or detainer or unlawful detainer, or at any time afterwards, may apply to the judge of the court in which the action is pending for a writ of restitution restoring to the plaintiff the property in the complaint described, and the judge shall order a writ of restitution to issue. The writ shall be issued by the clerk of the superior court in which the action is pending, and be returnable in twenty days after its date; but before any writ shall issue prior to judgment the plaintiff shall execute to the defendant and file in court a bond in such sum as the court or judge may order, with sufficient surety to be approved by the clerk, conditioned that the plaintiff will prosecute his or her action without delay, and will pay all costs that may be adjudged to the defendant, and all damages which he or she may sustain by reason of the writ of restitution having been issued, should the same be wrongfully sued out.