Setfenv; number expected, got table

So I added a pcall to my script, and now it prints out the error outside the env. It says attempt to call a table value, which I assume is a error outside the env

local outputlines = {}
	local scriptran = loadstring[[
		print("a")
	]]

	local env = getfenv(scriptran)
	
	local sandbox = setmetatable({
		print = function(...)
			table.insert(outputlines,(...))
		end,
		warn = function(...)
			table.insert(outputlines,(...))
		end,
		error = function(...)
			table.insert(outputlines,(...))
		end,
	},{
		__index = function(_,var)
			return env[var]
		end,
	})
	setfenv(scriptran,sandbox)
	local _, errorMsg: string = pcall(sandbox)
	if errorMsg then
		print(errorMsg)
	end
	scriptran()
	
	for i,v in ipairs(outputlines) do
		print(i,v)
	end
local outputlines = {}
local scriptran = loadstring[[
		print("a")
	]]

local env = getfenv(scriptran)

local sandbox = setmetatable({
	print = function(...)
		table.insert(outputlines,(...))
	end,
	warn = function(...)
		table.insert(outputlines,(...))
	end,
	error = function(...)
		table.insert(outputlines,(...))
	end,
},{
	__index = function(_,var)
		return env[var]
	end,
})
setfenv(scriptran,sandbox)

scriptran()
for i,v in ipairs(outputlines) do
	print(i,v) --1 a
end

This works for me (removing the attempt to call the environment table).

local outputLines = {}
local strFunc = loadstring("print('Hello world!')")
local strEnv = getfenv(strFunc)

local sandBox = setmetatable({
	print = function(...)
		table.insert(outputLines, (...))
	end,
	
	warn = function(...)
		table.insert(outputLines, (...))
	end,
	
	error = function(...)
		table.insert(outputLines, (...))
	end,
}, {
	__index = function(_, Key)
		return strEnv[Key]
	end,	
})

setfenv(strFunc, sandBox)
strFunc.print("Hello world!")
for _, Value in ipairs(outputLines) do
	print(Value) --Hello world!
end

Before you were calling the environment itself as opposed to calling one of its indexed functions.

Thanks, I see where I went wrong and it works now.