Cobalt sulfides as persulfate activator have received increasing interest in the field of persulfate-based advanced oxidation process. In this study, Co9S8 anchored in N, S, O heteroatoms co-doped carbon (CoSx@N-S-O-C) composite was prepared with different sulfur precursors (sulfur, thiourea, thiophene and benzyl disulfide), and used to activate peroxymonosulfate (PMS) for sulfamethoxazole (SMX) degradation. The effect of temperature, pH, inorganic ions, humic acids and water components on SMX degradation was investigated. The results showed that sulfur precursor could regulate the catalytic activity of the composite through changing the cobalt speciation and carbon structure. The catalytic activity was highest when the molar ratio of sulfur to cobalt was 5:1 (CoSx@N-S-O-C-5). Sulfate radicals (dominant) and hydroxyl radicals contributed to SMX degradation. The intermediate products during SMX degradation were identified, and the possible pathway of SMX degradation was proposed. Pyridinic N, Co-N, cobalt, S2−, S22−, C-S-C and C-SOx were active sites for PMS activation.