The production of activated carbon (AC) by recycling agricultural byproducts such as waste pineapple peel (PiP) is an example of a sustainable strategy for the environment and low-cost production. The pineapple peel activated carbon (PiPAC) was produced via the carbonization and two steps of the pyrolysis process, utilizing potassium oxide (KOH). Due to its high porosity, the PiPAC demonstrated strong adsorption capabilities for methylene blue (MB) and methyl red (MR) dyes. Characterization techniques, including Scanning Electron Microscopy (SEM), Fourier Transform Infrared (FTIR) spectroscopy and Energy-dispersive X-ray spectroscopy (EDX), were employed to analyze the PiPAC's performance. Response surface methodology (RSM) was used to optimize the preparation of PiPAC, where the activation temperature (AcTe) of carbon dioxide (CO2) (648.87-901.13 degrees C), activation time (AcTi) of CO2 (0.32-3.68 h), and impregnation ratio (IR) of KOH (0.15-4.35) were manipulated variables. The effects on MB and MR dyes adsorption of initial concentration (25-300 mg/L), contact time (24 h), and temperature (30-60 degrees C) were studied. For AcTe and AcTi of CO2 and KOH IR, the optimal PiPAC preparation conditions were 732 degrees C, 1.96 h and 3.0, respectively. Results showed the highest maximum adsorption capacity (qmax) for PiPAC-MB dye at 165.17 mg/g and PiPAC-MR dye at 94.87 mg/ g at 60 degrees C. Kinetic studies indicated that the overall process followed a pseudo-first-order (PFO) kinetic model, which influenced the film-diffusion-controlled mechanisms for both PiPAC-MB and PiPAC-MR dyes adsorption. The best described equilibrium isotherm studies Koble-Corrigan and Sips isotherm models for PiPAC-MR dye and the Temkin isotherm model for PiPAC-MB dye. The regeneration efficiency for the PiPAC-MB dye adsorbent in the third cycle was 83.70 %, supported with EDX and SEM. Overall, the work highlighted the novelty, greenness, and sustainability of utilizing waste PiP to produce AC and its application in wastewater treatment.