Context. The CHON generic chemical formula covers different isomers such as isocyanic acid (HNCO), cyanic acid (HOCN), fulminic acid (HCNO), and isofulminic acid (HONC); the first three have been identified in a large variety of environments in the interstellar medium (ISM). Several phenomena could be at the origin of the observed abundances, such as different pathways of formation and destruction involving gas phase reactions with different possible activation barriers and/or surface processes depending on the local temperature and the nature of the support. Aims. The scope of this article is to shed some light on the interaction of the CHON isomers with interstellar grains as a function of the nature of the surface and to determine the corresponding adsorption energies in order to find whether this phenomenon could play a role in the abundances observed in the ISM. Methods. The question was addressed by means of numerical simulations using first principle periodic density functional theory (DFT) to represent the grain support as a solid of infinite dimension. Results. Regardless of the nature of the model surface (water ice, graphene, silica), two different classes of isomers were identified: weakly bound (HNCO and HCNO) and strongly bound (HOCN and HONC), with the adsorption energies of the latter group being about twice those of the former. The range of the adsorption energies is (from highest to lowest) HOCN > HONC > HNCO > HCNO. They are totally disconnected from the relative stabilities, which range from HNCO > HOCN > HCNO > HONC. Conclusions. The possibility of hydrogen bonding is the discriminating factor in the trapping of CHON species on grain surfaces. Whatever the environment, differential adsorption is effective and its contribution to the molecular abundances should not be ignored. The theoretical adsorption energies provided here could be profitably used for a more realistic modeling of molecule-surfaces interactions.