Plants synthesize toxins through various biochemical pathways that involve complex cellular processes. These pathways are often activated in response to biotic or abiotic stress. For instance, when a plant is attacked by an insect, it may increase the production of certain alkaloids that deter or kill the pest. The capability of a plant to produce specific toxins is often genetically encoded, which can vary widely among different species.