The accumulation and transformation of lead (Pb) and arsenic (As) during the digestion of sewage sludge (SS) by black soldier fly larvae (BSFL) remain unclear. In this study, we used 16 s rRNA and metagenomic sequencing techniques to investigate the correlation between the microbial community, metalloregulatory proteins (MRPs), and Pb and As migration and transformation. During the 15-day test period, BSFL were able to absorb 34–48 % of Pb and 32–45 % of As into their body. Changes in bacterial community abundance, upregulation of MRPs, and redundancy analysis (RDA) results confirmed that ZntA, EfeO, CadC, ArsR, ArsB, ArsD, and ArsA play major roles in the adsorption and stabilization of Pb and As, which is mainly due to the high contribution rates of Lactobacillus (48–59 %) and Enterococcus (21–23 %). Owing to the redox reaction, the regulation of the MRPs, and the change in pH, the Pb and As in the BSFL residue were mainly the residual fraction (F4). The RDA results showed that Lactobacillus and L.koreensis could significantly (P < 0.01) reduce the reducible fraction (F2) and F4 of Pb, whereas Firmicutes and L.fermentum can significantly (P < 0.05) promote the transformation of As to F4, thus realizing the passivation Pb and As. This study contributes to the understanding of Pb and As in SS adsorbed by BSFL and provides important insights into the factors that arise during the BSFL-mediated migration of Pb and As.