Bioinsecticides are regarded as important alternatives for controlling agricultural pests. However, few studies have determined the persistence of these compounds in stored grains. This study aimed at optimizing and validating a fast and effective method for extraction and quantification of residues of safrole (the main component of Piper hispidinervum essential oil) in cowpea beans. It also sought to assess the persistence of this substance in the grains treated by contact and fumigation. The proposed method used headspace solid-phase microextraction (HS-SPME) and gas chromatography with a flame ionization detector (GC/FID). Factors such as temperature, extraction time and type of fiber were assessed to maximize the performance of the extraction technique. The performance of the method was appraised via the parameters selectivity, linearity, limit of detection (LOD), limit of quantification (LOQ), precision, and accuracy. The LOD and LOQ of safrole were 0.0057 and 0.019 μg kg−1, respectively and the determination coefficient (R2) was >0.99. The relative recovery ranged from 99.26 to 104.85, with a coefficient of variation <15%. The validated method was applied to assess the persistence of safrole residue in grains, where concentrations ranged from 1.095 to 0.052 µg kg−1 (contact) and from 2.16 to 0.12 µg kg −1 (fumigation). The levels measured up from the fifth day represented less than 1% of the initial concentration, proving that safrole have low persistence in cowpea beans, thus being safe for bioinsecticide use. Thus, this work is relevant not only for the extraction method developed, but also for the possible use of a natural insecticide in pest management in stored grains.