Opioids are a class of drugs that include both legal prescription pain relievers, such as morphine, codeine, oxycodone, and fentanyl, as well as illegal drugs like heroin. These substances are often prescribed for the management of severe or chronic pain, including pain associated with cancer.