Mild steel is a common material used in a variety of applications, including oil and gas pipelines, offshore structures, and chemical processing equipment. However, it is susceptible to corrosion in media containing H2S and CO2, which can lead to significant degradation and failure of the material. In this study, two new cationic (CBP) and non-ionic biopolyurethanes (NIBP), were synthesized based on castor oil as corrosion inhibitors for mild steel in H2S-CO2 environments. The effectiveness of these biopolymers in mitigating mild steel corrosion was assessed through electrochemical impedance spectroscopy, potentiodynamic polarization, and atomic force microscopy techniques. The results indicated that CBP and NIBP were effective in mitigating mild steel corrosion at a low concentration of 100 mu M, protecting the metal surface with efficiencies of 96.1 % and 94.9 %, respectively. The electrochemical and surface analysis showed that CBP and NIBP formed a protective layer on the mild steel surface, which hindered the corrosion process. Additionally, a biodegradability study demonstrated the eco-friendly nature of CBP and NIBP, achieving 38 % and 42.1 % biodegradation after 30 days. This sustainability aspect significantly bolsters their appeal for environmentally conscious applications. Our research presents compelling evidence for the successful use of castor oil-derived biopolymers as powerful, eco-friendly corrosion inhibitors, offering new possibilities for widespread adoption in oil and gas production, and other industries where efficient, environmentally responsible corrosion protection is vital.