Be shot how? Even at max range the horsemen can sit even further out and just leave some mobile scouts nearby. Your odds of a long range hit on a moving scout are slim to none and they'll still see if anybody comes out in time to warn the main force to ride you into the ground, if you try to get food in from outside they have to get past the cavalry, doubtful without multiple well armed regiments which you don't have. Try to get out to forage? You've got under half a mile where you have reasonable safety. Not even close enough to feed 4000 soldiers for long let alone a city. Try to go further out and cannons lose accuracy and a fast moving mobile army will sweep over you.
Besides which this isn't realistic. Your 4000 men are defending an entire city so they'll be spread very thinly and a single breach is all it'd take to force you off the walls. A single foothold and sheer numbers will soon overwhelm you since you can't counter attack without opeing yourself to another dozen, plus you have the spite of the dice and 17000 men who are better trained then most of those humans and a fair few of which have bows to thin out defenders on the wall. Plus it depends on the wall design and the length your defending. 10-1 on a wall designed for it thats small? Sure. 10-1 on a massive standard wall? Not a hope in hell.
4000 men is still a slim chance to hold the walls and still traps you inside to starve. Theres a reason sieges were almost always broken from the outside and it's impossible to break one without coming out or an outside force doing it. Your cannon don't have the range or accuracy over long distance to break a siege.
Look at the mongols for instance, they faced massive cities with numberically superior defenders who were well trained who had cannons.
That did not stop them conquering everything in there parth for generations with inferior equipment and lower numbers. Your facing an enemy that has almost every advantage. A small army inside a city might be able to hold the walls. Might.
But all your doing is bottling yourselves up to die unless somebody else sends a bigger army to break the siege.