Mishkat al-Masabih 122
On God’s words, “When your Lord took from the children of Adam from their backs their offspring,” 1 Ubayy b. Ka‘b said:
He gathered them and put them in pairs. Thereafter He fashioned them and endowed them with speech, and they spoke. He then made an agreement and covenant with them, calling them to witness regarding themselves, [saying] “Am I not your Lord?” They replied, “Yes.” He said, “I call the seven heavens and the seven earths to witness regarding you, and I call your father Adam to witness regarding you, lest you should say on the day of resurrection, ‘We did not know of this.’ Know that there is no god other than me and no lord other than me, and do not associate anything with me. I shall send to you my messengers to call to your remembrance my agreement and my covenant, and I shall send down my books to you. They replied, “We testify that Thou art our Lord and our God; we have no other lord and no other god but Thee.” So they confirmed that. Adam was raised above them and looked at them, and seeing the rich and the poor, the beautiful and those not so beautiful, he asked, “My Lord, why didst Thou not make Thy servants equal?” He replied, “I wanted to be thanked.” He also saw among them the prophets like lamps with light in them. They had another -special covenant concerning their mission and prophetic office, viz. His words, “And when we took from the prophets their covenant... Jesus son-of Mary.” 2 He was among those spirits and He sent him to Mary. Ubayy is quoted as saying that he entered by her mouth. 

Ahmad transmitted it. 1 ibid. 2 Quran, xxxiii, 7.
عَن أبي بن كَعْب فِي قَوْلِ اللَّهِ عَزَّ وَجَلَّ (وَإِذْ أَخَذَ رَبُّكَ مِنْ بَنِي آدَمَ مِنْ ظُهُورهمْ ذرياتهم وأشهدهم على أنفسهم)
الْآيَة قَالَ جمعهم فجعلهم أرواحا ثُمَّ صَوَّرَهُمْ فَاسْتَنْطَقَهُمْ فَتَكَلَّمُوا ثُمَّ أَخَذَ عَلَيْهِمُ الْعَهْدَ وَالْمِيثَاقَ وَأَشْهَدَهُمْ عَلَى أَنْفُسِهِمْ أَلَسْتُ بِرَبِّكُمْ قَالَ فَإِنِّي أشهد عَلَيْكُم السَّمَوَات السَّبْعَ وَالْأَرَضِينَ السَّبْعَ وَأُشْهِدُ عَلَيْكُمْ أَبَاكُمْ آدَمَ عَلَيْهِ السَّلَام أَنْ تَقُولُوا يَوْمَ الْقِيَامَةِ لَمْ نَعْلَمْ بِهَذَا اعْلَمُوا أَنَّهُ لَا إِلَهَ غَيْرِي وَلَا رَبَّ غَيْرِي فَلَا تُشْرِكُوا بِي شَيْئا وَإِنِّي سَأُرْسِلُ إِلَيْكُمْ رُسُلِي يُذَكِّرُونَكُمْ عَهْدِي وَمِيثَاقِي وَأُنْزِلُ عَلَيْكُمْ كُتُبِي قَالُوا شَهِدْنَا بِأَنَّكَ رَبُّنَا وَإِلَهُنَا لَا رب لَنَا غَيْرُكَ فَأَقَرُّوا بِذَلِكَ وَرُفِعَ عَلَيْهِمْ آدَمُ يَنْظُرُ إِلَيْهِمْ فَرَأَى الْغَنِيَّ وَالْفَقِيرَ وَحَسَنَ الصُّورَةِ وَدُونَ ذَلِكَ فَقَالَ رَبِّ لَوْلَا سَوَّيْتَ بَيْنَ عِبَادِكَ قَالَ إِنِّي أَحْبَبْتُ أَنْ أَشْكُرَ وَرَأَى الْأَنْبِيَاءَ فِيهِمْ مِثْلَ السُّرُجِ عَلَيْهِمُ النُّورُ خُصُّوا بِمِيثَاقٍ آخَرَ فِي الرِّسَالَةِ وَالنُّبُوَّةِ وَهُوَ قَوْلُهُ تَعَالَى (وَإِذ أَخذنَا من النَّبِيين ميثاقهم)
إِلَى قَوْله (عِيسَى ابْن مَرْيَم)
كَانَ فِي تِلْكَ الْأَرْوَاحِ فَأَرْسَلَهُ إِلَى مَرْيَمَ فَحُدِّثَ عَنْ أُبَيٍّ أَنَّهُ دَخَلَ مِنْ فِيهَا. رَوَاهُ أَحْمد