As a clean energy source, coalbed methane (CBM) produces almost no exhaust gas after combustion, and its extraction and efficient utilization play a key role in supporting sustainable development. Therefore, molecular dynamics simulations were used to research the diffusion of CH4 in coal after injecting CO2/N2 in different sequences and to clarify the efficiency of CBM extraction under different injection sequences, so as to contribute to sustainable development. The results show that the adsorption amounts of CO2 and N2 in different injection sequences are obviously different. To narrow the gap between the two injection amounts, the injection pressure of N2 can be appropriately increased and that of CO2 can be reduced, or N2 can be injected preferentially instead of CO2. When CO2 is injected first, the interaction energy between CH4 and coal is stronger and increases slightly with displacement time as a whole. The interaction energy curve of the N2 injection decreases, and the displacement effect becomes worse and worse. From the diffusion and relative concentration distribution of CH4, it can be seen that the diffusion of CH4 molecules outside the grain cell is more obvious when N2 is injected first. In terms of the number of CH4 molecules diffusing outside the crystal cell, it is less when CO2 is injected first than when N2 is injected first. The average value of the velocity distribution of CH4 increases slightly when CO2 is injected first and decreases significantly when N2 is injected first, but the average value is overall higher for N2 injection first. From the difference in diffusion coefficients before and after the gas injection, it can be seen that the decrease in permeability due to the expansion of the coal matrix by CO2 is more obvious than the increase in permeability due to the contraction of the coal matrix by N2.