In loose reservoirs, where the pressure and stresses around the wellbore are greater than the formation strength, the sand production problem is exacerbated. Sand production leads to a number of potential and costly problems. Chemical sand consolidation as a less costly method is performs to strengthen the oil well formation based on various polymer resins.In the present paper, a new epoxy-based nanofluid for controlling sand production with chemical strength was presented. Epoxy/g–C3N4–NS nanofluid has two special properties. First, a carbon nitride nanosheet as an active functional agent was used to increase the compressive strength of the epoxy resin after the curing process. Second, a bubbling agent was used to create micro and macro pores for production fluid movement and ultimately increase permeability. The FTIR, XRD, TEM, FESEM, and TGA analyses were performed to investigate and characterization of synthesized materials. The effect of different concentrations of resin, solvent, bubbling agent and g–C3N4–NS on the consolidation was studied. The compatibility of epoxy/g–C3N4–NS nanofluid with brine and crude oil from the Ahvaz oilfield was also investigated.The optimum amount of nanofluid composition containing resin, diluent, bubbling agent, and strength agent has a compressive strength of nearly 3000 psi and an absolute permeability of 4000 mD. The results of core flooding experiments showed that for synthetic plug samples whose initial permeability is more than 500 mD, after chemical consolidation with the epoxy/g–C3N4–NS nanofluid, the retained permeability was almost 86%. Based on the experiments conducted, the epoxy/g–C3N4–NS nanofluid was compatible with the brine and crude oil and it can be commercialized as a new formulation to control sand production in oil wells.