I got the answer.
In the bpy code at last I am doing:
const finalCode = `${userCode}\n\nfor obj in bpy.context.scene.objects:\n obj.select_set(True)\nbpy.ops.wm.usd_export(filepath="/workspace/${outputName}", export_textures=True, export_materials=True, export_animation=True)`
this exports in Universal Scene Description(USD) and save in a file(/workspace/outputName). Since ${tempDir}:/workspace, which is why the file is stored in ${tempDir}/${outputName}
I could give the output to user now.
Solved!