The Messenger of Allah ﷺ narrated to us - and he is the truthful and entrusted one: 'Indeed the creation of one of you is gathered inside his mother in forty days. Then, for a similar period, he is a clot. Then, for a similar period, he is a piece of flesh. Then Allah sends the angel to him to blow the soul into him, and he is ordered to write four (things): To write his provision, his life-span, his works, and whether he will be wretched or happy. By the One besides Whom there is none other worthy of worship! One of you will do deeds of the people of Paradise, until there is between him and it but a forearm span, then he is overcome by what is written for him, and he is sealed off with the deeds of the people of the Fire, so that he enters it. And indeed one of you will do deeds of the people of the Fire, until there is between him and it but a forearm span, then he is overcome by what is written for him, and he is sealed off with the deeds of the people of Paradise, so that he enters it.'" Another chain reports a similar narration.
حَدَّثَنَا رَسُولُ اللَّهِ ﷺ وَهُوَ الصَّادِقُ الْمَصْدُوقُ إِنَّ أَحَدَكُمْ يُجْمَعُ خَلْقُهُ فِي بَطْنِ أُمِّهِ فِي أَرْبَعِينَ يَوْمًا ثُمَّ يَكُونُ عَلَقَةً مِثْلَ ذَلِكَ ثُمَّ يَكُونُ مُضْغَةً مِثْلَ ذَلِكَ ثُمَّ يُرْسِلُ اللَّهُ إِلَيْهِ الْمَلَكَ فَيَنْفُخُ فِيهِ وَيُؤْمَرُ بِأَرْبَعٍ يَكْتُبُ رِزْقَهُ وَأَجَلَهُ وَعَمَلَهُ وَشَقِيٌّ أَوْ سَعِيدٌ فَوَالَّذِي لاَ إِلَهَ غَيْرُهُ إِنَّ أَحَدَكُمْ لَيَعْمَلُ بِعَمَلِ أَهْلِ الْجَنَّةِ حَتَّى مَا يَكُونُ بَيْنَهُ وَبَيْنَهَا إِلاَّ ذِرَاعٌ ثُمَّ يَسْبِقُ عَلَيْهِ الْكِتَابُ فَيُخْتَمُ لَهُ بِعَمَلِ أَهْلِ النَّارِ فَيَدْخُلُهَا وَإِنَّ أَحَدَكُمْ لَيَعْمَلُ بِعَمَلِ أَهْلِ النَّارِ حَتَّى مَا يَكُونُ بَيْنَهُ وَبَيْنَهَا إِلاَّ ذِرَاعٌ ثُمَّ يَسْبِقُ عَلَيْهِ الْكِتَابُ فَيُخْتَمُ لَهُ بِعَمَلِ أَهْلِ الْجَنَّةِ فَيَدْخُلُهَا