The top executives at Apple, Facebook, Google and Microsoft have stayed on the political sidelines during the 2018 midterm elections, opting not to donate to federal candidates who might advance Silicon Valley’s political agenda — or battle back President Trump.

Two years ago, these tech leaders emerged as some of Trump’s biggest critics, challenging his administration publicly on issues including immigration, climate change and gender equality. Personally, though, they’ve declined since then to write checks to congressional office-seekers who might serve as a bulwark against the White House, federal records show.

Apple CEO Tim Cook so far has backed one Democratic lawmaker in California, after spending nearly $500,000 — almost entirely on Democrats, and a few Republicans — during the 2016 presidential race, according to data published by the Federal Election Commission. Mark Zuckerberg, chief executive of Facebook, and Larry Page and Sergey Brin, co-founders of Google parent Alphabet, so far haven’t written any checks to federal candidates, the records show. All three companies declined to comment for this story.

Some executives are active: Sheryl Sandberg, chief operating officer of Facebook, has contributed nearly $300,000 in the 2018 election, FEC records reveal. Much of her support has gone toward nearly 30 Democratic women running for office, along with a super PAC that encourages women to vie for political office and cast ballots on Election Day.

The more cautious approach stands in contrast to these tech companies' own workers. By October, employees in the Internet industry had given more than $13 million to federal candidates and campaigns, about 85 percent of which has landed in the hands of Democrats, according to data from the Center for Responsive Politics.

In Silicon Valley, though, politics is a precarious business. On one hand, rank-and-file tech workers in the liberal-leaning Bay Area increasingly demand that their bosses sound off on national issues. But tech executives must balance the needs of their employees with the reality that they must maintain positive relationships with Democrats and Republicans alike. Cook, for example, has criticized Trump yet struck an effective personal relationship with the president. The official corporate political-action committees at other tech companies, including Amazon, Facebook and Google, similarly aim to donate equally to both parties as part of a broader strategy to stave off unwanted regulation.

“There’s no single formula explaining why CEOs make personal political donations, as it always involves some mix of cultivated personal chemistry, issue alignment with the company, the member’s future importance to the business and recognition of her prior support,” said Bruce Mehlman, executive director of the Technology CEO Council, which represents the leaders of companies like IBM, Oracle and Qualcomm.

In 2018, Microsoft CEO Satya Nadella hasn’t backed any federal candidates, FEC records show, though he’s previously donated sparingly. Neither has Twitter CEO Jack Dorsey. Microsoft and Twitter declined to comment. In contrast, Google CEO Sundar Pichai wrote two checks — one to a committee for Senate Democrats, another for Senate Republicans — earlier this year.

At Amazon, chief executive Jeffrey P. Bezos previously had donated little to political candidates — until August, when he made a $10 million donation to a super PAC that backs both Democratic and Republican office-seekers who have previously served in the military. Bezos and his top deputies have backed other lawmakers this cycle, including Republican Sen. Cory Gardner (Colo.). Amazon’s leaders held a fundraiser for Gardner at company’s Seattle headquarters, according to two people familiar with the event but not authorized to speak on the record. (Bezos owns The Washington Post.)

Gardner is a moderate Republican who sits on a key committee in Congress that oversees tech policy issues including privacy, artificial intelligence, and the universe of smart gadgets and wearables called the “Internet of things.” Spokesmen for the senator and Amazon did not respond to requests for comment.

Since 2017, Elon Musk, leader of SpaceX and Tesla, has donated nearly $200,000 — mostly to Republicans, according to FEC records. The donations came despite an earlier, public rift with Trump over his decision to withdraw the United States from an international climate accord. A person familiar with Musk’s thinking, who spoke on the condition of anonymity, said he has also contributed to two organizations to elect House and Senate Democrats — although the reports have not yet been filed with the FEC. A spokesman for the tech executive declined to comment.