Predators will refrain from attacking harmless insects if they look like insects that have stung them before.
"Attacking" is a present participle verb. It introduces the subordinate clause "attacking harmless insects", which is the complement of the preposition "from". "Harmless insects" is direct object of "attacking".