Enhancing the long-term moisture stability of perovskite solar cells remains a formidable challenge. In this study, we introduce an innovative approach involving in situ microencapsulation of grain boundaries using the polymeric epoxy curing reaction. This process involves the interaction between the epoxy resin of bisphenol A diglycidyl ether and the hardener of isophorone diamine to create a protective barrier at the perovskite grain boundaries. The microencapsulation serves a dual purpose: acting as a primary barrier for defect passivation and concurrently functioning as a secondary polymer spacer, effectively shielding the perovskite layer from water molecule intrusion. Consequently, the perovskite phase stability exhibits a remarkable 95-fold improvement against δ-FAPbI 3 and the accelerated formation of PbIOH under a relative humidity of 94%. The in situ microencapsulation not only improved the power conversion efficiency but also maintained 80% of the initial efficiency for 165 h under relative humidity of 70%.