Not sure if this is the right place to ask and sorry if this is a dumb question in which it seems fantasy like. But is it possible for an assassin to have a to kill a spy who is undercover, not that the assassin is aware of that. Sorry if this is broad.
It depends on the degree of fantasy, but this scenario could play out. It’s entirely plausible someone could be contracted to kill an undercover operative without either the assassin or the client knowing the target’s real affiliation. This could even be a result of the spy’s activities being identified as a threat, without realizing that they’re a professional.
For example: Organized crime corruption could incorrectly identify a spy as someone gathering information for law enforcement, rather than a foreign power. Similarly, an operative’s activities could interfere with organized crime (either intentionally or not), and become a target without the organization knowing what they’re really dealing with.
It’s also possible someone could hire an assassin to deal with a spy, but not tell their assassin about the target’s true occupation.
There’s two problems with this question, the first is simply, “what do you think an assassin and spy are?” The second is the phrase, “have to kill.”
“Have to kill,” is a little strange, as phrases go. It implies that they need to kill their target, rather than they were simply hired to do so. There are situations where this could happen, such as if the spy was a witness, or if the assassin’s target was someone the spy was close to, and the assassin doesn’t know anything about them except that they need to be dealt with. However, in a lot of cases, if the assassin realizes they were hired to go after a spy, and that information was withheld, it’s entirely reasonable they’d cancel the contract when they found out (and depending on their status, maybe even blacklist the person who took out the contract in the first place.) Though, obviously, that might not an option if the assassin isn’t a freelance killer.
Spies and assassins are both careers that are radically distorted in popular culture. The James Bond style superspy is a superhero variant, with about as much relation to real world espionage as Batman does to being a functioning, well-adjusted adult. Similarly, master-class assassins like 47 or John Wick don’t appear to exist in the real world. (There have been a handful of assassinations which are hard to pin down, but at the same time, the entire point of being an assassin is to go undetected, and it’s the amateurs who fail to get away with murder.)
With that in mind, depending on the level of fantasy you’re imposing, your spy could just be an individual with exceptional social engineering skills, and a technical background slightly more advanced than you’d expect given their cover story. They could also be a superhero, living a double life, with a suite of implausibly advanced gadgets hidden in their home.
Depending on the level of fantasy, your assassin could just be some guy with a .38 and a dream, or they could be a professional contracted by a shadowy international organization, with decades of experience, with an access to an arsenal of hardware that starts with “top-of-the-line,” and quickly ascends into borderline sci-fi.
There’s room for stories at either end of those spectrums, though mismatching them could have peculiar results. Somewhat obviously, a superspy vs superassassin story is going to be very different from an accountant with social skills vs a cheap hitman. There’s also room for either character to be the protagonist in those stories.
It’s also worth remembering, when you’re looking at the skillset of characters like Bond and 47, they’re both very similar. Bond isn’t an assassin by trade, but he has the skillset, and assassinates people on occasion. 47 isn’t a spy, but, he is incongruously skilled blending into a crowd, (to the point of parody.)
Ironically, an excellent example of this similarity is Jason Bourne. In the novels, he’s a spy undercover as an assassin (when he loses his memory), while in the (Matt Damon) films he always was an assassin.
On the low end, with a, “realistic,” spy, it’s entirely possible that their killer never learns about their real job. On the superhero end of the spectrum, that would be need-to-know information, and the assassin could be reasonably put out with their employer for withholding that detail.
While not 100% reliable, if you’re an evil mastermind, it wouldn’t be the worst way to dispose of an assassin who was becoming troublesome. Send them after some James Bond proxy’s cover identity and let the problem sort itself out. Worst case: You’ve dealt with one annoyance (either the assassin or the spy.) Best case: They’re both dead and you can go back to your evil masterminding business uninterrupted. I mean, it’s not like they could team up and come after you together, that would just be silly.