Instantiated prefabs in Editor are duplicated in Game mode

I am using a script to instantiate a lot of instances from a few prefabs, and I want this to happen in edit mode. If I use [ExecuteInEditMode] in my script, the instances appear correctly in the editor, but each time I enter game mode a copy is generated. Without [ExecuteInEditMode], the objects appear only in game mode (but I would like to see them in edit mode as well, before entering game mode).

How can I prevent game mode from generating that copy?

My basic script structure is this:

[ExecuteInEditMode]
public class InstantiateTest : MonoBehaviour
{
    public GameObject prefab;

    void Start()
    {
        var newObject = Instantiate(prefab, new Vector3(0,0,0), Quaternion.identity);
    }

    void Update()
    {
       // empty
    }
}

The script is attached to an Empty in the scene.

From a quick Google search, you can use Application.isEditor or Application.isPlaying to check if the game is running or in the editor.

Thank you very much, that was exactly what I needed! I did an entire afternoon of search before posting here, but I was evidently using the wrong keywords…