mattwparas / steel

An embedded scheme interpreter in Rust
Apache License 2.0
1.19k stars 53 forks source link

sandboxed environment errors out #264

Open jgeraerts opened 2 months ago

jgeraerts commented 2 months ago

I was trying to toy around with steel in a prototype I'm doing. Especially the sandboxed environment looked nice to me but it errors out when constructing.

A failing test demonstrating the issue:

  #[test]
    fn test_sandboxed_environment() {
        let mut engine = Engine::new_sandboxed();
        assert!(engine.compile_and_run_raw_program("(+ 1 1)").is_ok());
    }

---- steel_vm::engine::engine_api_tests::test_sandboxed_environment stdout ---- thread 'steel_vm::engine::engine_api_tests::test_sandboxed_environment' panicked at crates/steel-core/src/steel_vm/engine.rs:959:50: called Result::unwrap() on an Err value: SteelErr { repr: Repr { kind: FreeIdentifier, message: "Cannot reference an identifier before its definition: #%function-ptr-table", span: Some(0..0), stack_trace: None } } note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

mattwparas commented 2 months ago

Looks like I've got some bitrot there - will take a look

mattwparas commented 2 months ago

Okay, taking a look at this now - besides the obvious that it doesn't work, I just wanted to ask what you were hoping the sandboxed engine would do? I haven't spent a great deal of time hardening the sandbox explicitly, but I can easily disallow access to certain APIs and enable easy interruption.

However, it would be trivial for someone to simply allocate an incredibly large list - there are currently no guard rails for that. If you're interested in something like that, I can start plumbing through protections for that kind of thing and start making headway

jgeraerts commented 2 months ago

I was looking to use it as a prototype - dsl around datafusion oriented code. So ideally I could register custom functions and only allow control-flow constructs, basic math etc etc. But you don't need to bother with it for me specifically. I just wanted to report it so you were aware.

mattwparas commented 2 months ago

Got it - so I'll follow up with some fixes here and an example of how you can achieve that soon (hoping either this evening or tomorrow evening)

If you ever post the data fusion code publicly, let me know! I'm also interested in steel wrapping data fusion in some way