Other companies have tried to prevent employees from using everything from Uber to cigarettes. In 2015, IBM banned employees from using ride-sharing apps, citing safety and liability concerns. (Employees rebelled, and the company did a U-turn a day later.) And several big employers, including General Electric, have successfully paid employees to quit smoking. Scotts Miracle-Gro even has a policy of not hiring smokers, a move it says helps keep health care costs down.

In some of these cases, the values of a few executives are imposed on workers who must adhere to their employers’ worldview, often relating to issues with scant connection to the business. But WeWork appears to be the first big company to tell its employees what they can and can’t eat.

“Human beings really don’t like when you take choice away from them,” said Laszlo Bock, the former senior vice president of people operations at Google and the author of “Work Rules!”

“What people are much more amenable to is nudges,” he said. “How can you change the environment that doesn’t remove choice, but sends a signal for people to make a good decision?”

Mr. Bock has personal experience with vegetarianism. While he was at Google, two of the many cafes at company headquarters tried out “meatless Mondays,” going vegetarian for just one day a week. Employees rebelled, throwing away silverware and staging a protest barbecue.

Meatless Mondays didn’t last at Google. But in time, the company made changes to the cafeterias — like offering smaller plates and making salad bars more prominent — that improved employees’ eating habits.

“When you exercise this level of control over employees, even with good intentions, it often backfires,” said Heather Bussing, an employment lawyer in Northern California. “Just because you really believe this is the right thing to do, not everyone will agree with you.”