How do I spawn objects randomly near an object then delete them?

Hi I am making a top down 3d endless runner type game and I am struggling to figure out how to make “x” number of obstacles spawn in front of the player in random positions on the x Axis then disappear after a small amount of time.

Are the objects being placed all at once or within a certain time frame? If all at once you can use a for statement:

for(int i = 0; i < amount; i++){
Instantiate(prefab, origin + Vector3.right * Random.Range(-1,1), Quaternion.identity);
}

If within a time frame for better performance:

StartCoroutine(createPrefabs());

IEnumerator createPrefabs(){
    int i = 0;
    While (i < amount){
    I++;
    Instantiate(prefab, origin + Vector3.right * Random.Range(-1,1), Quaternion.identity);
    yield return new waitForEndOfFrame();
    }
}

For the prefab, attach a script to it that destroys itself after waiting some time through an invoke():

    void Start(){
    Invoke("kill", seconds)
    }
    
    void kill{
    Destroy(gameObject);
    }