private void runInNewEnvironment() {

		// Create new interpreter and stick it in the script's state.
		final GhidraJythonInterpreter interpreter = GhidraJythonInterpreter.get();
		final PrintWriter stdout = getStdOut();
		final PrintWriter stderr = getStdErr();
		interpreter.setOut(stdout);
		interpreter.setErr(stderr);

		// We stick the interpreter in the state so that if the script calls runScript, that
		// script will use the same interpreter.  It is questionable whether or not we should do 
		// this (the new script will get all of the old script's variables), but changing it now
		// could break people's scripts if they expect this behavior.
		state.addEnvironmentVar(JYTHON_INTERPRETER, interpreter);

		// Execute the script in a new thread.
		JythonScriptExecutionThread executionThread =
			new JythonScriptExecutionThread(this, interpreter, interpreterRunning);
		interpreterRunning.set(true);
		executionThread.start();

		// Wait for the script be finish running
		while (interpreterRunning.get() && !monitor.isCancelled()) {
			Thread.yield();
			sleep100millis();
		}
		if (interpreterRunning.get()) {
			// We've been canceled. Interrupt the interpreter.
			interpreter.interrupt(executionThread);
		}

		// Script is done. Make sure the output displays.
		stderr.flush();
		stdout.flush();

		// Cleanup the interpreter, and remove it from the state (once it's cleaned it cannot be
		// reused)
		interpreter.cleanup();
		state.removeEnvironmentVar(JYTHON_INTERPRETER);
	}
Runs this script in a new interpreter environment and sticks the new interpreter
in the script state so it can be retrieved by scripts called from this script.
Ghidra/Features/Jython/src/main/java/ghidra/jython/JythonScript.java