Duloxetine works by increasing the levels of serotonin and norepinephrine in the brain and spinal cord. These neurotransmitters play a crucial role in regulating pain and mood. By inhibiting their reuptake, duloxetine helps to alleviate pain and improve the psychological well-being of patients undergoing cancer treatment.