If there are going to be more than one or two wishes in your game, you really should spend some thought deciding on general principles of how they work. As an example, I do it this way.
Wish is not the greatest power in the multiverse. Their are deities and other mythic beings that can surpass wishes and do things it can't. Therefore you first look at something in terms of that. I this something only gods should be able to do? Then it's probably beyond a wish.
I would go even further (and simplify it) by phrasing it more like "is this something that is likely to upset the gods?" If the answer is yes, it's probably beyind the power of a wish. The alternative would be having gods regularly interfere with or punish wishes, which is a complication I don't think is intended.
Second, wish is a 9th level spell, so it is generally (see below) limited to the power of 9th level spells. So when a wish happens, first see if there is a way to make it one true that invokes a similar amount of power as other 9th level spells.
"I wish I had a staff of the magi!". "Best I can do is teleport you to the treasure room where a testy archmage keeps one." "I wish my opponent were dead! "Best I can do is move you ahead in time to after he has died."
Finally, although it is technically limited to the power of a 9th level spell, the specific design of wish does allow it to push behind that power with complications. I run it so that it encompasses the most powerful magic mortals can wield, and epic magic is a subset and application of wishes. (Because I run 5e which doesn't have epic magic rules, and think it's easier to run it this way.)
So what happens when a wish is for something within the purview of mortal magic, but beyond a 9th level spell?
The magic, if it can, whether accomplishing something of 9th level power or greater, achieves the goal by following the path of least resistance, which typically means probably undesirable side effects. This isn't because the wish is malevolent, it's because it is trying to do what you want it to, and it only has so much magical power to do so. If it can accomplish the goal within its power "budget", by cutting corners on methodology (as in the "best I can do" examples) it will.
It only goes beyond that if it can't do it that way. Generally because the player phrases it precisely enough that it can't do it the easy, 9th-level, way, but it's still within the purview of mortal magic. So then what? Remember how I mentioned a "budget"? What do you do when you go over? You're going to have to borrow (or steal) energy. Or, the way I run it, you incur a magical debt, which you can think of like an electrical charge, that has to be balanced by an opposite charge.
This is the part where you get apparently malicious side effects, because there isn't enough power in the spell to just do it. The overdraft causes a type of magical backlash of rebalancing.
"I wish I had a staff of the magi, not owned by someone else, right here in my possession, without it disappearing or going back where it came from as a side effects!" Well, if you had left out that last part, that very well might have happened. The wish might have created one out of nothing for like one or two rounds, and then it vanished, returning it's magic to the multiverse.
But you were "smart". And apparently not an experienced caster who knows how these things work. It's not an internal contract, it's an energy budget, and you insisted on exceeding it and must somehow pay.
Best case scenario is their is actually an un-owned staff of the magi somewhere. It teleports it to you with complications. Perhaps it wasin the Elemental Plane of Fire, and now you get a temporary planar bleed within the surrounding area you will likely have to deal with. Or maybe it is buried under a mountain, and you get the mountain, etc.
But, more likely it can't find an un-owned one. So it has to make one. It might come with a curse or drawback of some sort. Maybe it drains your hit points (and max hit points until you complete a long rest) every time you use it. Or better yet, it permaently reduces your max hit points to make it out of your own essence. Hopefully you are high level so you aren't left with 1 max hit point. Or, more interestingly, maybe it takes crafting components from across the multiverse to make it. Some of those are fine, but some of those are owned by others (but not the staff itself, see hiw it's trying to be helpful!) who are going to come looking.
Worst case scenario, because you tried to make an iron-clad phrasing making it difficult to find a comfortable path of least resistance, it just straight up invokes a negative side effect completely unrelated to anyrhing. Fully functional staff of the magi appears with no strings attached. Now a pit fiend just randomly hates you. Or that hermit's hut on the hill over there explodes in a ball of fire, killing the hermit and starting a forest fire. Or your teammate disintegrates and requires a quest and a true resurrection to bring back. Whatever.
Now, archmages who learn the spell (rather than non-archmages getting it from an item or something) should know how this all works, and the DM should tell them when they are pushing the power limit, or outright exceeding it, so they know what level of trouble (but not the details) they are getting into. Remember, wishes are not malicious, that try their darndest to give you what you ask for.
Enter epic magic. Epic magic is no more or less than casting a wish spell that exceeds 9th level power (while staying within mortal power) while deliberately providing the extra energy needed in a controlled manner to eliminate unforseen side effects.
Let's say you want to make a staff of the magi, but you don't want to go through the normal magic items creation process. This isn't the best example because the magic items rules are there for a reason, and seeking to circumvent them should almost never be the way to go. But we'll take that into account in the cost. So, pretend you've just slain a dragon and have it's hoard. This hoard is worth 5 time what it would cost to create a staff of the magi, but doesn't have the correct components. You can probably have a wish consume the entire hoard and make the staff, as long as you throw in some other mystically significsn to element. Cast it at the right sort of conjunction, sacrifice some other magic items if significant but lesser value etc. But the biggest reason why this example isn't something you would do is because you need time (and money) to research how to cast this epic spell in the first place. It might be theoretically possible that the total time required is less than that needed to make the staff the normal way, and being on a very urgent schedule is about the only reason you would use this much less efficient method.
But most of the time, epic magic is used not to duplicate something you can do without it, but to accomplish something there is no other way of accomplishing. In that case, researching how it can be done, gathering the resources and meeting the magical conditions, and casting that wish to pull it altogether, is a safe and relatively reliable way to get effects beyond 9th level, but within the purview of mortal D&D magic.