Nitrogen and sulfur codoped carbon dots (SB-CDs) were developed from sugar cane bagasse, an agro-industrial waste, and evaluated as an eco-friendly corrosion inhibitor for Q235B steel in HCl solution. The surface coverage of the adsorbed SB-CDs is strongly influenced by immersion time (6 and 72 h, both in static and dynamic conditions) and inhibitor concentration (20-200 mg/L). Maximum and uniform coverage is achieved with 150 mg/L SB-CDs. At this concentration, SB-CDs demonstrated a high inhibition efficiency of 96% after 6 h of immersion, maintaining effectiveness at 94 and 92% under static and dynamic conditions, respectively, at 72 h of immersion. Electrochemical studies showed that polarization resistance (Rp) increased, and corrosion current density (Icorr) of steel decreased in the presence of SB-CDs compared to uninhibited specimens, confirming SB-CDs' adsorption on metal surfaces. Additionally, surface analysis using scanning electron microscopy and atomic force microscopy confirmed the improved surface morphology and fewer corrosion features, supporting the formation of a protective film. Energy-dispersive X-ray and X-ray photoelectron spectroscopy analyses further confirm the formation of a protective layer by SB-CDs, attributed to the interaction of nitrogen-, oxygen-, and sulfur-containing functional groups with the steel surface. Therefore, a homogeneously adsorbed inhibitor layer entirely blocks the formation of iron chloride/oxide/hydroxide intermediates, ensuring high corrosion inhibition efficiency of Q235B steel in corrosive environments.