‘Umar ibn Ḥafṣ narrated to us; my father narrated to us; al-A’mash narrated to us; Zayd ibn Wahb narrated to us;
‘Abdullāh narrated to us: The Messenger of Allāh ﷺ — and he is the truthful, the believed — said: Indeed, each one of you is gathered in his mother’s womb for forty days; then he becomes a clinging clot for a similar period; then he becomes a lump of flesh for a similar period. Then, Allāh sends to him an angel with four words, and it is written: his deeds, his lifespan, his provision, and whether he will be unhappy or happy. Then, the soul is breathed into him. By Allāh, a man may perform the deeds of the people of the Fire until there is only a cubit between him and it, then what has been written overtakes him, so he performs the deeds of the people of Paradise and enters it. And a man may perform the deeds of the people of Paradise until there is only a cubit between him and it, then what has been written overtakes him, so he performs the deeds of the people of the Fire and enters it.”
Reference: Sahih Al Bukhari 3332