Monsters attack the same way they do everything else: through narration and GM moves.
So if Fightgar's in a dungeon and you want some goblins to attack Fightgar, it's simple as:
Endbringer makes quick work of the lock, and also the part of the door where the lock is. Fightgar, you push it open to a minimum of commotion, but the light from the hallway does spill into the dark room. Your eyes have enough time to adjust and make out the three goblins quarreling over a pile of loot in the middle of it before they realize they're being watched and leap to their feet.
And then their knives are out and they're rushing you, Fightgar. What are you doing?
Narration and a GM move - you've put Fightgar in a spot. Now, despite appearances, this is a pretty neutral spot. Fightgar can Hack and Slash here just fine - he and the goblins are on even ground with no overpowering advantages or disadvantages. But he doesn't have to Hack and Slash - he could quickly scan the battlefield to make sure he's taken everyone's measure (Discern Realities), turn tail and try to evade the goblins (Defy Danger), or buy them off with some more loot for the pile (Parley).
But let's suppose you want to force Fightgar's hand, set up a scenario that, if this were a video game, would be "the monsters strike first!" You'd need a little setup for this, but it can be as simple as: the dungeon is the Ruins of the Ambush Goblins, and according to your prep, just walking around in the Ruins of the Ambush Goblins is going to get you ambushed.
The Ambush: Starting with Disadvantage
However, keep in mind that you're there to be a fan of the players and fill their lives with adventure. Starting from a neutral position, just straight-up dropping damage on somebody isn't very adventurous and doesn't contain much to be a fan of -- and you've already got that impulse, right? It feels like there should be something that determines whether or not "the attack is successful", that you should be able to go, like--
Your torch creates patterns of light and shadow on the arched ceiling as you press forward, Fightgar. Suddenly, there's a movement, and you spin and raise your torch just in time to see a goblin leaping from a ceiling nook, brandishing a wicked-looking knife. "Glory in shadow!" it screams. You only have a split-second to react. What are you doing?
And now Fightgar's on the back foot! You're not necessarily "forcing a move" out of them, they still have some freedom to react, but they are at a disadvantage and you should feel free to tell them the requirements or consequences and then ask if they try and do something that assumes they're on an even keel - sure, you can draw Endbringer and attack the goblin in melee, but the goblin's got the drop on you, literally, and you will take at least one stab in addition to whatever results from your Hack and Slash.
Probably the only move that won't have this sort of rider is Defy Danger -- not because it's the "a monster is attacking you, dodge" move, but because it's useful for moving out of a temporary disadvantage state and back to even. You shouldn't be regularly calling for Defy Danger during combats - if Fightgar is an even match for what they're fighting, it's likely to stay that way.
That Solitaire Look
Now, both of these bits of narration assume something - the GM's license to make moves when the players look at them to find out what happens. In a conventional game, Fightgar's player doesn't know what will happen when he breaks the lock on the door, or what happens when he explores the Ruins of the Ambush Goblins. (He probably has suspicions in the latter case, but the GM's the only one who knows for sure.) When you're playing solo, are you looking at yourself to find out what happens... all the time? None of it? Somewhere in between?
In the case of solo play, a useful heuristic to keep in mind is that moves often bracket the conversation between GM and player. When a player makes a player-facing move, they're usually looking at the GM to adjudicate the results, except for certain special cases where they've set up Aid or Defy Danger to immediately chain into another followup move and they hit the first move clean. And in order to keep the game moving, when the GM finishes their part of the conversation, they close with a GM move to prompt a response from the player. The response from the player is the key there - when the player has given a definitive response, that brackets their end of the conversation. A player-facing move is one type of definitive response, but other things can be as well, such as a dramatic decision - for instance, to delve into the Ruins of the Ambush Goblins.
If you still find yourself wondering whose turn it should be, follow your instincts from how a conversation would go if it were two people talking. You've been having conversations for a lot longer than you've been playing Dungeon World, I hope.
The Less Neutral Setup
You don't give yourself golden opportunities very often in solo play, I imagine. Usually they require some differing threshholds for risk between the players and the GM, which is hard when they're the same person. But something that will come up often for you is a 6-.
For instance, Fightgar wisely attempted to Discern some Realities about the Ruins of the Ambush Goblins but unwisely rolled a 4 -- now you have a little more leeway to have the monsters start out successful, in keeping with your prep:
What should you be on the lookout for, Fightgar? Well, you sweep the torch around as you walk and -- oh, wow. Those aren't just shadows behind the pillars and the ceiling trim. This whole place is shot through with tunnels! How deep do they run? What's in them? Oh gods they could come from anywhere. It's almost a relief when a goblin takes a flying leap from the ceiling screaming "Glory in shadow!" and clamps onto your torso. The wicked-looking knife that sinks into your shoulderblade is less of a relief -- take d8 damage, piercing 1. Oh, and you've got a goblin clamped onto your torso ready to do the same thing again. What are you doing?
And the damage is not a threat like it was in the prior two scenarios, it's already done. If Fightgar's got a hand weapon he's probably fine to fight the goblin off himself, otherwise he's looking at some travails to dislodge his passenger.
But should monsters attack?
I've been using just plain ol' deal damage in these examples, but keep in mind that you're also here to give every monster life:
Think about more than just the exchange of damage. Monsters might be trying to capture the characters or protect something from them. Understand what the fight is about; what each side wants and how that might affect the tide of battle.
"The GM -- Fights", from the repo here
So, what do the monsters want? "Blood and pain" is a fine answer, especially for, say, a starved ocelot or a wandering patrol of mindless undead or, yes, a goblin ambusher, none of whom are particularly big-picture thinkers. But considering how monsters might react more than just trying to knock down player hit points can present a lovely complicated picture of combat. Suppose that opening example went like this instead:
Endbringer makes quick work of the lock, and also the part of the door where the lock is. Fightgar, you push it open to a minimum of commotion, but the light from the hallway does spill into the dark room. Your eyes have enough time to adjust and make out the three goblins quarreling over a pile of loot in the middle of it before they realize they're being watched. The one with their back to the door dives headlong into the pile, scooping most of it up and sprinting deeper into the darkness. The other two curse their lack of initiative and leap to their feet.
And then their knives are out and they're rushing you, Fightgar, while their erstwhile comrade makes a getaway. What are you doing?
You can see how this might give Fightgar a greater incentive to use those alternatives to Hack and Slash I mentioned - just fighting might let the one with the treasure get away, so maybe try and slip past the two in front, or buy them off, or take a quick look around for anything to take advantage of.
And, of course, other monsters might want different things, as evidenced in their instinct or their moves, and so when they have the PCs at a disadvantage, or even when they don't, they might choose to do something different.
- A giant eagle is going to hunt by dashing you on the rocks, so its opening move is not to just hurt you, but to pull you into the air.
- A hobgoblin slavetaker wants to take slaves, so it'll manacle your arms or legs when it gets the chance.
- Ossian, the lich, wants to channel the power of the stellar convergence without interference, to keep on un-living, so he puts into motion the ritual of the Hundred Mirrors, separating you and your companions from each other, and from most of reality.
But none of these are that different in execution from dealing damage - if they're intended to catch the PCs off guard, then present them as an imminent threat the PCs must react to, or if the PCs gave you an opening, just make them happen.