The only thing verse 8 of surah Shams mentions is that God’s “do’s and don’ts” have been transmitted to the people and they, using their minds and conscience they have been endowed with by Allah, can easily distinguish between vice and virtue. Therefore, this verse isn't saying that evil comes from God. Also, although many Islamic philosophers have taken it to be clear that existence is good, and that goodness is something existential, and that evil is actually privation and absence of good and not something that exists in and of itself, but this is only one of the different takes on the issue. According to other opinions, even if evil is seen as something existential, the problem of evil and theodicy will still be resolvable.
True, some verses of the Quran may imply that some evil comes from God, but it must be kept in mind that if evil is taken to be privation, the contrariety between good and evil will be that of privation and possession, and not that of contradiction, and as we all know, in the contrariety of privation and possession, absence isn't total and bears existence to some extent, and it is in this sense that evil is ascribed to its doer.
Before delving into the answer to the question itself, a few points and reminders need to be made:
1. What is the meaning of verse 8 of surah Shams “فَأَلْهَمَها فُجُورَها وَ تَقْواها”?
In response to this question, we must say that this verse has engaged in one of the most important matters pertaining to the creation of man, meaning the ‘inspiration’ of vice and virtue. What the verse is saying is that when man was created and his existence was complete, Allah taught him his “do’s and don’ts”.
“ألهمها” derives from the root “الهام” which originally means to eat or drink something, and here, has been used to denote transmission of something from the Lord to the soul and spirit of man; it is as if the soul actual takes in and ‘drinks’ it. This term has also been used to denote revelation at times. “فجور” derives from “فجر” which means to split and tear something vastly. It is due to this literal meaning that the dawn has been given the name “فجر”; it is as if the morning light tears the veils of night. The same goes for why sins have been given the same name; sin tears the veils of religiosity. Of course, what is meant by “فجور” in the discussed verse denotes the means and causes of sin, and what is meant by “تقوا”, which derives from “وقایة” (abstinence), is for one to keep himself from ugliness, inappropriateness, vice and sin.
It is also imperative to note that the verse isn't saying that Allah has created the means of sin and piety in man, and in other words, He hasn’t given man the faculties that invite him to depravation and tearing the veils of chastity, along with the means for being good and righteous, as opposed to what some believe. What the verse is actually saying is that He taught man these two, or, to put it more simply, he showed him the way to both, as verse 10 of surah Balad also reads: “وَ هَدَيْناهُ النَّجْدَيْنِ” (and shown him the two paths [of good and evil]).
In other words, Allah has given him a mind, ability of discernment and a vigilant conscience to be able to distinguish between vice and virtue through the aql (mind) and fitrah (primordial nature of man). Thus, some commentators have said that this verse is pointing to ‘intellectual good and evil’ (al-husn wa al-qubh al-aqli), which means those goods and evils that the mind can identify on its own without the dictation of religion; this is something that Allah has endowed man with. Of course, it must be kept in mind that it is by virtue of informed discretion and choice that man can reach his ultimate goal of perfection and goal of his creation; this means that man’s perfection is a matter of free will and acquisition. It is from this perspective that in the verses to follow the aforementioned verse, the Quran attributes purification and corruption to man himself: “قَدْ أَفْلَحَ مَنْ زَكَّاه وَ قَدْ خابَ مَنْ دَسَّاها”.
2. It would have been better if you had asked the question in a different way by saying that some verses mention that good and evil all belong to Allah, while other verses tell us that good is only from Him and evil is from man, and that man’s selection and actions play a role in there being evil; some evil originates from man’s decisions, such as moral corruptions, transgression, oppression, poverty, hunger, and hundreds of other economical, political, and medical complications the world faces. Also, there are some evil that are linked to our actions through causality, an example being certain worldly and otherworldly punishments. Therefore, evil must be something existential, while philosophers believe it to be something non-existential and rather, define it to be privation. If this is the case, then why have these verses ascribed evil to God, while it isn't something existential that can be created? How can we reconcile between these two sets of assertions?
To answer this question, one must say:
a) Based on the theory that holds evil to be privation in essence, the contrariety between good and evil will be one of ‘privation and possession’ (al-adam wa al-malakah) and not one of ‘contradiction’ (al-tadhadd), and as we all know the privation in the former, bears a degree of existence, as opposed to privation in the latter, and this degree of existence can be ascribed to its doer.
To explain further, divine ideology holds that everything is the creation of God and that everything has been created in perfection. That which has to do with God, is creating, which isn't apart from perfection and goodness, and all the hardship and calamities which are either evil in nature or evil in human actions, are in reality privation of good and thus, not the creation of God. In the verses mentioned previously, the only evils that are spoken of are those having to do with man’s actions. The point these verses look teach us is that what deprives man of divine blessings are the actions we do at an individual and social level, and of course, this doesn’t contradict the fact that evil is privation and not a creation of God’s.
As one scholar put it, earth orbits around the sun and one side of it is always facing the sun, making it day, and if the other side of the globe is dark, it is because it is away from the sun; the sun is always doing its job of radiating light. Therefore, one can say that whichever part of the earth is bright, is because of the sun, and the part that is dark is because of earth itself and not the sun. So, from the perspective that man himself, and his free will are all under the dominance of God, one can ascribe evil to God, but from the perspective that only good is issued from God, if evil is ascribed to Him, it will be due to the origin of this evil – in its privational sense – being existential. The same goes for ascribing evil to man, with one difference though: since man has the opportunity to benefit from divine blessings and the ‘radiation of the sun’, and yet chooses to turn away from and deprive himself of it, he consequently deserves punishment. In any case, the contrariety between good and evil is one of ‘privation and possession’ and the privation in such cases, possesses a degree of existence and isn't total privation, and it is due to this degree of existence that it can be ascribed to its doer, the same way creation of death, which is essentially privation, is ascribed to God: “الَّذي خَلَقَ الْمَوْتَ وَ الْحَياةَ لِيَبْلُوَكُمْ أَيُّكُمْ أَحْسَنُ عَمَلاً وَ هُوَ الْعَزيزُ الْغَفُورُ”.
b) Different religious and non-religious interpretations and definitions are proposed when it comes to the meaning of evil. For example, from a non-religious philosophical perspective, evil can be interpreted as the following:
1. Privation; 2. Relativity; 3. Inseparability of good and evil; 4. The abundance of good over evil; 5. Evil being a preliminary step to good; 6. Evil: particularism and materialism; 7. Evil: accidental and a by product; all the explanations given above were actually based on only one philosophical interpretation of the many theories regarding the essence of evil. Based on other interpretations, one can look at evil as existential and continue with the discussion from there.
To conclude, one must say that verse 8 of surah Shams doesn’t want to say that evil comes from God, all it wants to say is that the “do’s and don’ts” have been taught to man by God, and he can, using the mind and vigilant conscience he has been endowed with, distinguish between vice and virtue. Of course, some verses imply that evil can be ascribed to both God and man, but one must keep in mind that such attribution is due to the existential origin from which this non-existential matter originates, and is also due to the fact that this non-existential evil, isn't totally non-exist and rather, is non-existent in the sense of privation (adam al-malakah), thus, bearing a degree of existence.
 في أصول الكافي باسناده الى حمزة بن محمد الطيار عن ابى عبد الله عليه السلام حديث طويل و فيه يقول عليه السلام و قال: «فَأَلْهَمَها فُجُورَها وَ تَقْواها» قال: بين لها ما تأتى و ما تترك.. Tafsir Nour al-Thaqalayn, vol. 5, p. 587.
 Of course some commentators believe the difference between “وحی” and “الهام” to lie in the fact that the person receiving ilham doesn’t know from where he received what he was given, while the one who receives wahy knows from where it is coming and through whom.
 Tafsir Nemouneh, vol. 27, pp. 46 and 47.
 Ma’aarife Islami, vol. 1, p. 109; for further information, see: The reason for deviating from the straight path, Question 164 (site: 1194); Man and free will, Question 9835 (site: 9855); Guidance of Man, Question 631(site: 690); Man and predestination and free will, Question 1896 (site: 2718); Man’s free will and divine guidance, Question 3451 (site: 3702).
 Shams:9 and 10.
 Nisa’:79, “ما أَصابَكَ مِنْ حَسَنَةٍ فَمِنَ اللَّهِ وَ ما أَصابَكَ مِنْ سَيِّئَةٍ فَمِنْ نَفْسِكَ” (Whatever good befalls you is from Allah; and whatever ill befalls you is from yourself)
 We have proven in its own place that although some rewards and punishments are a result of ‘designation’, some are due to the causal relationship between our actions and their respective rewards; meaning that our action is the cause, and its inevitable effect is the reward or punishment. To put it more precisely, the reward or punishment is the deed itself, which manifests on the Day of Judgment.
 That which is considered to be the essential source of evil is an aspect of imperfection pertaining to an existent capable of possessing perfection contrasting with it. See: Misbah Yazdi, Muhammad Taqi, Philosophical Instructions, p. 562.
 Zumar:63 “اللَّهُ خالِقُ كُلِّ شَيْءٍ”.
 Sajdah:7 “أَحْسَنَ كُلَّ شَيْءٍ خَلَقَهُ”.
 As a result of this, in surah Nisa’, the Quran tells man that any goodness that may befall him is from Allah and any evil is his own work. The reason for this is that since evil is done by man, it is associated with him, and since man and his will are all under God’s dominance, it is associated with God; the same way if in an office, a worker does something wrong, it is associated to both himself and the government, because he is a worker of the government. Imam Rida says: “Allah addresses man saying: Your will and decision is mine also.” (Tafsir Ayyashi, vol. 1, p. 258). See: Tafsir Nur, vol. 2, p. 336; Tafsir Nemouneh, vol. 4, p. 24, Nur Jame’ al-Tafasir Software.
 Plato has been quoted to say that through philosophical analysis, we can say that blindness, deafness, ignorance, sickness and any other form of evil, are respectively the absence of sight, the absence of hearing, the absence of knowledge, and the absence of strength and health. So, evil is actually privation in essence, and privation has no place in the system of causation, thus freeing us of the problem of associating these with God. The majority of Islamic philosophers have also deemed existence to be goodness, and good to be existential and see this as self-evident; they have also considered evil being privative as self-evident. See: Tabatabai, Muhammad Husayn, Bidayat al-Hikmah, p. 159, Nur al-Hikmah Software.
 We have no total evil in this world; all the things that are considered to be purely bad, such as floods and earthquakes, wild animals, germs and sickness, are actually evil for some creatures, and yet good for others. The poison of the snake isn't bad for the snake itself, although it might be considered bad for the human and other creatures that are harmed by it.
 The natural world is one of motion and conflict and clashing. Material entities are evolving from their potential state to a state of actualization of these potencies. Sometimes in this path and while in motion, conflict and clash take place, making it infeasible to separate good from evil. Thus, the only way for this world to be pure good and devoid of any form of evil, is for it to not have motion and not be material (so to say that “The world has no evil” is a negative proposition due to the lack of a subject, as philosophers say, the same way the proposition “Jesus’ father was a good person” is; because Jesus had no father to begin with, and since this proposition has no subject in reality, it is a negative one; so if there is to be no evil, there will have to be no world to begin with; having a world is equal to having evil), and if the there is to be no world because we don’t want to have motion and material, then much good will be negated, and this negation of good is in itself, a great evil. In other words, if the natural world ceases to exist, we will be freed of some evil, but will also lose out on much good. Also, many evils such as differences are due to geographical and regional variance, and these types of evil are something nature essentially entails.
 Although there is evil in this world, nonetheless, the evil never outweighs the good. If it ever is to happen that the evil outweighs the good, the world will cease to exist and will perish, so, the continuation of this world shows that the good are outweighing the evil.
 Hardship, calamities, tragedies and difficulties play an important role in scientific, spiritual, industrial, technological, etc., development. In other words, the only way man’s potentials are realized is through making it through the ups and downs and putting up with problems and hardship. Therefore, evil is sometimes the cause of much good.
 The concept of things being considered as evil, stems from particularism, whereas, if one was to step back and look at the bigger picture, he would see that one’s home is in need of a restroom, no matter how bad and unnecessary a restroom may seem from up close, and no matter how bad it smells. Also, some things seem evil because of the materialistic view by which they are looked at, while if one takes into consideration the hereafter as well, that same thing will no longer be evil. Take death for instance, for one who only sees this world, it is privative and evil, but for the believer, it is only a transition from one world to another. So, to sum it up, some things may be taken to be evil at first sight, while the truth of the matter is the exact opposite; in other words, with a broader and comprehensive view, the exact opposite becomes manifest.
 It is also sometimes said: God essentially has intended good, although accidentally (bil-arad), He has also intended evil. Therefore, evil isn't something directly intended by God, rather, it is accidentally (accidentally in its philosophical sense) intended and in other words, isn't but a mere by product so to speak.