Player agency has been a pretty hot topic in the old school gaming blogosphere. In case you've missed all of the excellent treatments of the subject by more illustrious bloggers than I, the gist is that the players should be able to make real choices, and those choices should affect outcomes in the game. This is opposed to the "railroad" style of game, where player choice is limited and exerts a limited effect on the events of the adventure, in order to achieve a desired story progression or outcome. So far as I'm aware, though, nobody has devoted much attention to the other side of the coin - the agency of the players' adversaries in the adventure. Villain agency is an important consideration in fostering player agency; after all, the players' choices are much less meaningful if the adventure is inevitably going to end in a pitched battle with the villain and his top henchmen in the Big Room of Climactic Combat.
Not every adventure will even have a villain in the usual sense of the word, of course, but the standard formula in those that do is usually a classic railroad from the villain's point of view. The Big Bad commits some nefarious act, holes up in the last room at the bottom of the dungeon, and waits there for the party to come beat the stuffing out of him/her/it. Aside from the inciting incident of the adventure, the villain's role is mostly passive, his destiny a preordained death at the hands of the heroic adventurers. At most, the villain has pre-programmed acts to commit at various points to keep the plot moving ahead, leaving the DM to constrain the PCs so as not to render the villain's next scripted action a complete non-sequitur.
In a true sandbox campaign, though, a villain should be able to react to the heroes' interference with his plans, either to thwart them or to try to stay one step ahead. He should be able to use all his wits and every resource at his disposal to achieve his diabolical aims, or failing that, to escape and fight another day. He should be able to roll with the punches and adapt to changing circumstances. His defeat shouldn't be preordained any more than the PCs' victory should be.
What the villain chooses to do depends on several factors: The villain's personality and goals, his current circumstances, the resources available to him, and most importantly, what he knows.
First, know your villain. Who is he? What is his ultimate objective? What are his tastes and preferences and preferred methods? Is he subtle or straightforward, cruel or cloying, treacherous or honorable, cold and calculating or hot-tempered? A brutal warlord, a scheming royal adviser, and an ancient dragon might react very differently to the same situation.
Next, figure out the channels through which the villain receives information and is apprised of his plan's progress, both in his lair and in the wider world beyond. In order to take action and deploy his resources, a villain needs information. While it's possible for a bad guy to be oblivious to the PCs until they're knocking down the door to his throne room on dungeon level 10, it isn't likely, and having it occur frequently strains credibility. Any villain worth his salt should be keeping tabs on his plans, at least occasionally. This could include regular reports from his lieutenants and flunkies, personal inspections of key areas either openly or by stealth, magical scrying, non-human spies such as birds or rats, or tripwires and other traps that trigger alarms.
How long does it take him to become aware that a band of adventurers is snooping around his hideout and slaughtering his minions? How much can he learn about them and what they're up to, and how quickly? If he has informants in town, he might know before the party even sets out. Any minions who survive an encounter with the heroes will likely rat them out, and may be able to give a detailed account of their appearance and abilities. Even if the PCs leave no survivors, they're sending a message, albeit delayed and ambiguous, when the minions are missed.
How much the villain can discover about the PCs will certainly affect how he reacts to them. Their mere presence in his lair could mean they're just another band of looters, an inconvenience but not a dire threat. If he knows that they're investigating something for which he's responsible, the threat level goes up a notch, and if he learns that they're carrying the magical Macguffin that can ruin his plans, it's Defcon 1!
It probably goes without saying (but I'll say it anyway) that it's critically important to keep villain knowledge separate from DM knowledge. If there's no way for the villain to know something, he shouldn't act on it, and if the players manage to keep information from him, or feed him misinformation, or use whatever of his faults and foibles they might deduce or discover against him, they should absolutely reap the rewards of clever strategy.
What the villain does with what he knows depends on his personality as well as a few other factors.
What is he doing currently, and how important is it to his overall goal? A villain whose current objective is to sacrifice the king's daughter at a particular evil shrine during a particular celestial alignment has very different options open to him than one who is patiently gathering an army of monsters and brigands in the remote hills of the kingdom.
What is his relationship to the people or creatures who share his lair? Are they ideologically committed to his cause? Does he secure their cooperation through bribery, fear, or blackmail? Are they just neighbors, indifferent to him and his plans, or even unwitting innocents? Or are they as hostile toward him as they are toward the PCs when they descend into the dungeon?
What resources are available to him? Consider not only material and monetary resources, but his connections in the campaign world. Is he on good terms with a tribe of ogres or the shadier elements in the local merchants' guild? Does he have the king wrapped around his little finger, or the peasants of the kingdom duped into thinking he's a champion of the people? Does he have some dirt on the captain of the guard to compel his cooperation? How much time does he have?
Depending on the villain's temperament, resources, circumstances, and information, any number of options for action are open to him when heroes come crashing through his gates. Here are just a few...
Mobilize the lair's defenses.
Try to buy off the party to leave him alone.
Try to dupe or mislead the party into furthering his plans.
Deploy minions to divert or distract the party, either to buy time or to lead them into an ambush or an area where they can be confined.
Step up the timetable of his plans.
Relocate to another area in the dungeon, possibly leaving a trap or ambush in the original location.
Fortify his location.
Lay some false clues and misinformation in the party's path.
Attempt to goad the party into rash action.
Prepare an escape plan.
Emerge to confront the intruders.
Mount an all-out search and destroy mission.
Send for reinforcements if time allows.
Bottom line: If the villain can't or won't make choices in response to the players' choices, how far does their agency really extend? At the end of the adventure, whether the villain succeeds, fails, or escapes, it's much more satisfying to feel that it happened because the party's plans and actions outmaneuvered the villain's best efforts (or vice versa,) not merely because their characters' combat stats were better than his.