This paper addresses the critical security challenges in the internet of things (IoT) landscape by implementing an innovative solution that combines convolutional neural networks (CNNs) for feature extraction and the XGBoost model for intrusion detection. By customizing the reptile search algorithm for hyperparameter optimization, the methodology provides a resilient defense against emerging threats in IoT security. By applying the introduced algorithm to hyperparameter optimization, better-performing models are constructed capable of efficiently handling intrusion detection. Two experiments are carried out to evaluate the introduced technique. The first experiment tackles detection through binary classification. The second experiment handles the task by specifically identifying the type of intrusion through multi-class classification. A publicly accessible real-world dataset has been utilized for experimentation and several contemporary algorithms have been subjected to a comparative analysis. The introduced algorithm constructed models with the best performance in both cases. The outcomes have been meticulously statistically evaluated and the best-performing model has been analyzed using Shapley additive explanations to determine feature importance for model decisions.