Although cesium lead halide perovskite (CsPbX3, X = Cl, Br, or I) nanocrystals (PNCs) have been rapidly developed for multiple optoelectronic applications due to their outstanding optical and transport properties, their device fabrication and commercialization have been limited by their low structural stability, especially under environmental conditions. In this work, a new approach has been developed to protect the surface of these nanocrystals, which results in enhanced chemical stability and optical properties. This method is based on the encapsulation of CsPbX3 NCs into a polyimide with intrinsic microporosity (PIM-PI), 4,4′-(hexafluoroisopropylidene)diphthalic anhydride reacted with 2,4,6-trimethyl-m-phenylenediamine (6FDA-TrMPD). The presence of 6FDA-TrMPD as a protective layer can efficiently isolate NCs from an air environment and subsequently enhance their optical and photoluminescence stability. More specifically, comparing NCs treated with a polymer to as-synthesized nanocrystals after 168 h, we observe that the PL intensity decreased by 70% and 20% for the NCs before and after polymer treatment. In addition, the PNC film with a polymer shows a much longer excited-state lifetime than the as-synthesized nanocrystals, indicating that the surface trap states are significantly reduced in the treated PNCs. The enhancement in chemical and air stability, as well as optical behavior, will further improve the performance of CsPbBr3 PNCs yielding promising optical devices and paving the way for their production and implementation at a large scale.