To understand Saudi Arabia's role in the Middle East and in the world — which many Americans are coming to see as counterproductive at best and destructive at worst — one of the most important things to know is that Saudi foreign policy is shaped not just by foreign events but by the monarchy's fears of political opposition at home.
There are three categories of domestic political opposition that the Saudi regime sees as a threat to its hold on power: 1) Muslim Brotherhood–linked Sunni Islamists, 2) Salafi jihadists, and 3) Shia.
(Obviously not all Shia in Saudi are politically active or oppose the regime, but the point is that members of this persecuted minority have long agitated for more rights and better treatment.) These groups are not well-defined political parties with explicit political agendas, but rather are general categories of people, some of whose members share similar political and religious views and who have at times challenged the legitimacy of the Saudi royal family.
Since these groups have no legitimate way to express their political views — for instance, by having representatives in a parliament — they will sometimes link up with outside actors in the region whose political views mirror theirs and whose money, influence, or power can, they hope, help them achieve their political goals in Saudi Arabia.
The ties between the groups may be strong and involve direct financial or other support, but more often they are less tangible — closer to a feeling of solidarity and moral support than direct ties.
The Islamists have been linked with the Muslim Brotherhood, which has individual branches in almost every Arab country and briefly held power in Egypt in 2012 and 2013 before being overthrown in a military coup supported by Saudi Arabia. The Salafi jihadists have ties to al-Qaeda, ISIS, and other militant Islamist groups fighting in Iraq and Syria. The Shia have religious and communal ties to other Shia in the region, including in Lebanon, Iraq, Yemen, and especially Bahrain.
But more importantly, the Saudi regime believes the Shia who are agitating for change in Saudi Arabia are backed by Iran. Although most experts believe these ties to be vastly overstated by the Saudi regime, the point is that Saudi leaders believe it to be true.
This is part (though not all) of why Saudi Arabia sees those foreign actors as so threatening and can overreact to them — because they see them as linked to the domestic opposition groups they really worry about.
That fact helps explain why Saudi Arabia is spending billions of dollars propping up the Sisi regime in Egypt that overthrew that country's democratically elected Muslim Brotherhood government in 2013. Saudi Arabia is also fighting a costly and devastating war against the Houthis in Yemen and, in 2011, sent troops to crack down on the mass uprising against the Sunni ruling family of Bahrain by the country's Shia majority.
Syria shows the problems this dynamic can create for Saudi leaders. They see the Iranian-backed Assad regime in Syria as part of a broader "Shia crescent" of Iranian influence encroaching on Saudi Arabia and threatening to inflame their Shia minority at home. So when the war against Assad got underway, Saudi saw an opportunity and began supporting jihadist groups fighting Assad. The problem is that the Salafi jihadists they're funding in Syria are also linked to Salafi jihadists back in Saudi Arabia — who directly threaten the Saudi regime.
Eventually, any Saudi jihadists fighting in Syria or Iraq will come home — battle-hardened and far more intimately connected to powerful jihadist organizations with money and resources — and may turn their attention once again to the Saudi monarchy they see as illegitimate apostates.
Obviously many other factors help explain Saudi foreign policy as well. In the case of Shia, the Saudi fears of domestic opposition threatening the regime itself are overblown. But the point, as I've written previously, is that an awful lot of Saudi Arabia's behavior, particularly its seemingly most shortsighted and damaging actions, are driven in large part by regime insecurity and fear that the monarchy could lose power. When you look at Saudi behavior in the region that way, it doesn't look any better, but at least it makes more sense.