Innate Spellcasting. Baalagog's innate spellcasting ability is Charisma, and requires no material components to use magic (spell save DC 17).
Tunneler. Baalagog can burrow through solid rock at half its burrow speed and leaves a 10-foot-diameter tunnel in its wake. Legendary Resistance (3/Day). If Baalagog fails a saving throw, it can choose to succeed instead
Multiattack. Baalagog makes two bite attacks. Bite. Melee Weapon Attack: +14 to hit, reach 10 ft., one target. Hit: 22 (3d8 + 9) piercing damage. If the target is a Large or smaller creature, it must succeed on a DC 19 Dexterity saving throw or be swallowed by Baalagog. A swallowed creature is blinded and restrained, it has total cover against attacks and other effects outside Baalagog, and it takes 21 (6d6) acid damage at the start of each of the Baalagog's turns. If Baalagog takes 30 damage or more on a single turn from a creature inside it, they must succeed on a DC 21 Constitution saving throw at the end of that turn or regurgitate all swallowed creatures, which fall prone in a space within 10 feet of Baalagog. If the Baalagog dies, a swallowed creature is no longer restrained by it and can escape from the corpse by using 20 feet of movement, exiting prone. Frightful Presence. Each creature of the Baalagog's choice that is within 120 feet of them and aware of them must succeed on a DC 19 Wisdom saving throw or become frightened for 1 minute. A creature can repeat the saving throw at the end of each of its turns, ending the effect on itself on a success. If a creature's saving throw is successful or the effect ends for it, the creature is immune to the Baalagog's Frightful Presence for the next 24 hours Fire Breath (Baala, Recharge 5–6). Baalagog exhales fire in a 60-foot cone. Each creature in that area must make a DC 21 Dexterity saving throw, taking 63 (16d6) fire damage on a failed save, or half as much damage on a successful one. Sand Breath (Gog, Recharge 5–6). Baalagog lets loose a torrent of sand in a 90-foot line that is 5 feet wide. Each creature in that line must make a DC 19 Dexterity saving throw, taking 66 (12d10) bludgeoning damage on a failed save, or half as much damage on a successful one. A creature who fails the save is pushed 60 ft backwards.
Baalagog can take 3 legendary actions, choosing from the options below. Only one legendary action option can be used at a time and only at the end of another creature's turn. Baalagog regains spent legendary actions at the start of their turn. Detect. The dragon makes a Wisdom (Perception) check. Dive. Baalagog tunnels under the ground and emerges 30ft from its current space. Bite (Costs 2 Actions). Baalagog makes one bite attack. Thrash (Costs 2 Actions). Baalagog thrashes their body, causing tremors in the sand. Each creature within 10 feet of the dragon must succeed on a DC 22 Dexterity saving throw or take 15 (2d6 + 8) bludgeoning damage and be knocked prone. The dragon can then up move to half its move speed.