Though Cook helms one of the world's biggest technology companies, he said technology is "not always the solution," and is sometimes part of the problem. He said that shareholders have pushed Apple to focus on return on investment, but that engineers should have the courage to stand by what is right.
"Most of the time [technology] is a force for good," Cook said. "But the potential adverse consequences are spreading faster and cutting deeper than ever before. Threats to our security, threats to our privacy, fake news, and social media that sometimes becomes anti-social."
Technology must be infused with decency and kindness, Cook said.
"I'm not worried about artificial intelligence giving computers the ability to think like humans," he said. "I'm more concerned about people thinking like computers."
He warned graduates that though the internet has empowered many, sometimes the "basic rules of decency are suspended" and pettiness thrives.
"I'm optimistic because I believe in your generation," Cook said. "There's so much out there conspiring to make you cynical. ... Don't listen to trolls."
Cook was chosen for his role as a "trailblazer" in championing innovation, MIT said in a statement.
Cook said joining Apple — under Steve Jobs' strong vision — lifted a "psychological burden," freeing him to indulge in work that served humanity.
"How can I serve humanity? This is life's biggest and most important question," Cook said. "The question I hope you will carry from here is, 'How will you serve humanity?'"
Cook noted in a statement that Apple employs many MIT graduates.
"MIT and Apple share so much. We both love hard problems, we love to search for new ideas, and we especially love finding these ideas — the ones that change the world," Cook said.
The iPhone maker has been a strong advocate of technology education. Apple has pledged $100 million to bring technology and services into 114 underserved schools across the United States, and $40 million to a partnership with the Thurgood Marshall College Fund, according to its latest proxy statement.
The CEO told the MIT Technology Review on Thursday that he hopes Apple technology will protect people's privacy, even when using tools like machine learning to address the ills of humankind.
On a lighter note, Cook joked that MIT's strong history of pranks, or hacks, might be behind President Donald Trump's use of Twitter: "I know college students are behind
— CNBC's Lora Kolodny contributed to this report.