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 it, because most of the tweets happen at 3 a.m."
— CNBC's Lora Kolodny contributed to this report.