ingame scripting

I’ve began researching ways to incorporate a scripting engine into the game I’m making so that players can program their way through the game.
For example, the player is being chased and writes a script that tells the ground to open up and swallow his enemies.

My question is, would it be possible to write, edit, and incorporate scripts in game in real time
If so where should I begin
I know this is a big question
I’m primarily wanting to know if this is even possible

This is indeed a big question. If you’ve seen Project Spark from MS, you could do something like that: give the player a predefined set of Actions / Decisions / to chose from and adjust game tendencies from those. It’s not a simple thing to do but you could start with a small graphical based POC and go from there.

The specific example you’ve given though is extermely difficult if taken literally (i.e. actual terrain tear/ground swallowing). You could alter the concept a bit to ‘drop’ a GameObject behind the player that mimics the desired behavior (mob enters GObj and drops below ground/Y val then destroyed).

Anyway, if you are just starting you will be better off trying something simple to see if your concept and abilities align. For example, start with a GUI that allows the player to instruct an AI/companion to favor a melee v ranged enemy, or whatever fits your game setting.