node_vm2 icon indicating copy to clipboard operation
node_vm2 copied to clipboard

Sandbox option not working as expected

Open Shadlington opened this issue 3 years ago • 1 comments

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?

Shadlington avatar Sep 22 '22 14:09 Shadlington

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"}}')},
)

eight04 avatar Sep 30 '22 09:09 eight04