Coder Social home page Coder Social logo

Extending require() further about vm2 HOT 4 CLOSED

somebody1234 avatar somebody1234 commented on May 17, 2024 1
Extending require() further

from vm2.

Comments (4)

bmewj avatar bmewj commented on May 17, 2024 4

Somewhat relevant: I'm using a custom file system for user submitted code. Is there a way I can manually deal with local requires, like require('./otherUserSubmittedFile'), fetching the file from the custom file system and handing it over to vm2 to then sandbox?

Update:
Very rough, but have implemented something along the lines of custom/virtual files: https://github.com/bartjoyce/vm2-with-custom-fs

Usage, would be something like this:

NodeVM.file('/customfs/main.js', {
  require: {
    external: true,
    root: '/customfs/', // restrict local requires to within the custom fs
  },
  customfs: {
    getFileContents: (filename) => /* handle /customfs/ file read */,
    exists: (filename) => /* ... */,
    isDirectory: (filename) => /* ... */
  }
})

from vm2.

callumlocke avatar callumlocke commented on May 17, 2024 1

@bartjoyce I need the same thing! Your link is broken, did you move it somewhere?

from vm2.

bmewj avatar bmewj commented on May 17, 2024

@callumlocke I've since moved on to other projects and have stopped maintaining the code. The code I wrote is here: https://github.com/bartjoyce/vm2/

It's 30 commits behind, but at least you can see the modifications I've made.

Important commit is this one: bmewj@302e910

I've made additional changes to vm2 that are not in my repo. If you want to see those too, let me know.

from vm2.

stale avatar stale commented on May 17, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from vm2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.