Tricky, indeed! I hadn't looked at Lua before, and from what I gather, luaposix (namely, setenv in the luaposive.stdlib module) would appear to be one way to avoid sending actual commands to the terminal. But this still leaves out Windows . . .
I assume instructions for setting the environment variable are already included with the CDP tool. Maybe the most "portable" way of dealing with the problem would be just to check that environment variable has been set with os.getenv("CDP_SOUND_EXT") and simply ask the user to set it before proceeding?