Chemistry drives many biological interactions between the microbiota and host animals, yet it is often challenging to identify the chemicals involved. This poses a problem, as such small molecules are excellent sources of potential pharmaceuticals, pretested by nature for animal compatibility. We discovered anti-HIV compounds from small, marine tunicates from the Eastern Fields of Papua New Guinea. Tunicates are a reservoir for novel bioactive chemicals, yet their small size often impedes identification or even detection of the chemicals within. We solved this problem by combining chemistry, metagenomics, and synthetic biology to directly identify and synthesize the natural products. We show that these anti-HIV compounds, the divamides, are a novel family of lanthipeptides produced by symbiotic bacteria living in the tunicate. Neighboring animal colonies contain structurally related divamides that differ starkly in their biological properties, suggesting a role for biosynthetic plasticity in a native context where biological interactions take place.