He called on the graduates, likely including plenty of future tech leaders, to find purpose in their work by putting human needs front and center. But he also acknowledged society's struggles with technology's downsides.
Cook began his 20-minute speech on an upbeat note, describing the common ground between his company and the venerable university.
“MIT and Apple share so much. We both love hard problems. We love the search for new ideas, and we especially love finding those ideas, the really big ones, the ones that could change the world.”
But Cook suggested that while MIT grads could expect to accomplish great things, a deep sense of meaning may be the hardest thing to achieve in the end. He described his own long struggle to answer the big questions: “Where’s all this going . . . What is my purpose?”
Get Data Sheet, Fortune’s technology newsletter.
“I kept convincing myself that it was just over the horizon, around the next corner,” he said. But through 15 years of career advancement, meditation, and religious and philosophical quests, Cook said, “nothing worked, and it was really tearing me apart.”
Cook found his answer when he joined Apple in 1998 under CEO Steve Jobs. He connected instantly with the company’s uniquely clear and decisive mission.
“It was just that simple: serve humanity. It was in that moment, after 15 years of searching, something clicked,” Cook said. To illustrate that mission and its challenges, he told a more recent story about rebuffing a shareholder who objected to Apple’s unprofitable environmental initiatives. According to Cook, he ultimately told the critic that he "shouldn’t own Apple stock.”
Cook called on the new MIT grads to marshal their skills to help tackle issues from cancer to inequality to climate change. But he cautioned that “technology alone isn’t the solution. And sometimes it’s even part of the problem.” Among the problems bred by technology, Cook cited were “threats to our security, threats to our privacy, fake news, and social media that becomes anti-social." He continued that, "Sometimes the very technology that is meant to connect us, divides us.”
As an alternative, Cook reiterated Jobs’ frequent dictum that technology should be guided by the insights of the humanities and liberal arts. “If science is a search in the darkness,” said Cook, “then the humanities are a candle that shows us where we’ve been, and the danger that lies ahead.”
Though the road ahead is fraught, Cook said he is “optimistic, because I believe in your generation, your passion, your journey.”
Cook’s speech wasn’t all grim warnings and grand challenges. He also worked in mild jabs at both Windows computers and President Donald Trump, applauding MIT pranksters who had “obviously . . . taken over the President’s Twitter account. I can tell college students are behind it because most of the tweets happen at 3 a.m.”