To predict the risk of in-hospital death in patients with chronic heart failure (CHF) complicated by lung infections using interpretable machine learning. The clinical data of 1415 patients diagnosed with CHF complicated by lung infections were obtained from the MIMIC-IV database. According to the pathogen type, the patients were categorized into bacterial pneumonia and non-bacterial pneumonia groups, and their risks of in-hospital death were compared using Kaplan-Meier survival curves. Univariate analysis and LASSO regression were used to select the features for constructing LR, AdaBoost, XGBoost, and LightGBM models, and their performance was compared in terms of accuracy, precision, F1 value, and AUC. External validation of the models was performed using the data from eICU-CRD database. SHAP algorithm was applied for interpretive analysis of XGBoost model. Among the 4 constructed models, the XGBoost model showed the highest accuracy and F1 value for predicting the risk of in-hospital death in CHF patients with lung infections in the training set. In the external test set, the XGBoost model had an AUC of 0.691 (95% CI: 0.654-0.720) in bacterial pneumonia group and an AUC of 0.725 (95% CI: 0.577-0.782) in non-bacterial pneumonia group, and showed better predictive ability and stability than the other models. The overall performance of the XGBoost model is superior to the other 3 models for predicting the risk of in-hospital death in CHF patients with lung infections. The SHAP algorithm provides a clear interpretation of the model to facilitate decision-making in clinical settings.