The tolerance advantages of nanobodies (Nbs) provide a new proposal for enhancing the stability and sensitivity of immunosensors. However, the tolerance of Nbs to extreme pH levels, has not been deeply investigated, as previous stability studies on Nbs had primarily focused on temperature and organic solvents. Here, a nanobody clone (NbFM5) is obtained and its tolerance is analyzed using molecular simulation and molecular docking. The simulation results reveal that the seven amino acids of NbFM5 and the ligand formed a "closed-loop" hydrophobic interaction pocket with highly electronegativity surface potential and net charges, which enhanced stability of configuration under varying pH conditions, thus ensuring the stability of the affinity. The results indicate that NbFM5 exhibited a mean antigen binding activity of 79.8 % across a pH range of 6 to 10 with standard deviation of 10 %, demonstrating high stability against a wide range of pH values. Given above, an aggregation-induced emission nanoparticles based lateral-flow biosensor is successfully established using NbFM5. The whole process of detecting procymidone is completed in 10 min with a detection limit of 0.19 ng/mL. The method has fully satisfied the need of rapid detection requirements in extreme environmental conditions and could establish a promising foodborne contaminants detection platform.