node_vm2
node_vm2 copied to clipboard
Sandbox option not working as expected
I may have misunderstood how this is supposed to work, but I believe that if I add an object to the sandbox option, it should be available as a global when the code executes in the VM.
My test code is here:
with node_vm2.VMServer() as server:
with node_vm2.VM(
server=server,
options={
"timeout": 500,
"allowAsync": False,
"wasm": False,
"sandbox": {"input": json.loads('{"data": {"foo": "bar"}}')},
},
) as vm:
print(vm.run("input.data.foo"))
I would expect input to be available, but instead I get the error "input is not defined".
Is this not working correctly, or have I misunderstood how this should be used?
You should pass those options as keyword arguments:
with node_vm2.VM(
server=server,
timeout=500,
allowAsync=False,
wasm=False,
sandbox={"input": json.loads('{"data": {"foo": "bar"}}')},
)