Artificial intelligence can be a force for good, but society needs to be careful to make sure its negative aspects do not outweigh its positives, Salesforce co-founder Marc Benioff told CNBC's Jim Cramer on Wednesday.

"AI has tremendous opportunity, but technology is never good or bad, it's what we do with the technology that matters," the billionaire entrepreneur and philanthropist said on "Mad Money."

Benioff, co-CEO and chairman of Salesforce, said there could be "dramatic consequences" as AI use in the military accelerates, for example. The Pentagon released its first AI strategy in February.

"But we can use AI for good as well," said Benioff, who is promoting "Trailblazer," the new book he co-authored with Salesforce executive Monica Langley.

Benioff pointed to a drone project that Salesforce is undertaking alongside experts from the University of California, Santa Barbara.

AI experts from Salesforce are working with university researchers to analyze drone footage, in almost real time, to identify great white sharks off the Southern California coast. Shark activity off the California coast has increased in recent years, prompting safety concerns for beachgoers.

"I just showed you how we have a drone running in Santa Barbara with AI, which spotted a great white shark heading for a surf camp," Benioff told Cramer. "And they called the beach, able to get the kids off the beach — that's AI for good."

Benioff said he considers AI to be one of the central components of the Fourth Industrial Revolution, which is "characterized by a fusion of technologies that is blurring the lines between the physical, digital, and biological spheres," according to the World Economic Forum.

"There's a lot of AI for good, there's gonna be AI for other things too," Benioff said. "We need to keep our eye on both."