In this study, a biochar-based magnetic solid-phase microextraction method, coupled with liquid chromatography-mass spectrometry, was developed for analyzing fentanyl analogs from urine sample. Magnetic biochar was fabricated through a one-step pyrolysis carbonization and magnetization process, followed by an alkali treatment. In order to achieve desired extraction efficiency, feed stocks (wood and bamboo) and different pyrolysis temperatures (300-700 • C) were optimized. The magnetic bamboo biochar pyrolyzed at 400 • C was found to have the greatest potential for extraction of fentanyls, with enrichment factors ranging from 58.9 to 93.7, presumably due to H-bonding and π-π interactions between biochar and fentanyls. Various extraction parameters, such as type and volume of desorption solvent, pH, and extraction time, were optimized, respectively, to achieve the highest extraction efficiency for the target fentanyls. Under optimized conditions, the developed method was found to have detection limits of 3.0-9.4 ng/L, a linear range of 0.05-10 μg/L, good precisions (1.9-9.4% for intrabatch, 2.9-9.9% for interbatch), and satisfactory recoveries (82.0-111.3%).The developed method by using magnetic bamboo biochar as adsorbent exhibited to be an efficient and promising pretreatment procedure and could potentially be applied for drug analysis in biological samples.