<p dir="auto">I'm creating a server in Deno that will be able to run user submitted scripts as "applications".</p>
<p dir="auto">The script/application will be imported dynamically (first time running the script) and cached by deno for subsequent requests.</p>
<p dir="auto">The script/application should by default have <code class="notranslate">read</code> access to its folder and only that specific folder. (It needs this permission so that it can run in the first place since its dynamically imported).</p>
<p dir="auto">To make sure that the foreign scripts/applications don't violate the read permission, (bear in mind that permissions granted apply to the whole server, not just the module/script that requested it), I have only one foreign script/application running at any given time. Once it's done, i revoke its permissions in-case i need to call another foreign script/application during the same request.</p>
<p dir="auto">Seeing that for each script that I ran I have to grant and deny permissions per request, and I know the permission each script needs ahead of time, is there a way to programaticaly Grant a permission?</p>
<p dir="auto">Here is a portion of my entry point to load the scripts/apps:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="this.router.get(&quot;/:application&quot;, composeMiddleware([err, setPermissions]), async (context, next) =&gt; { 

           let application = await import(`./Applications/${context.params.application}/${context.params.application}.ts`)

           new application.default(context, next, this.router)  
   })"><pre class="notranslate"><code class="notranslate">this.router.get("/:application", composeMiddleware([err, setPermissions]), async (context, next) =&gt; { 

           let application = await import(`./Applications/${context.params.application}/${context.params.application}.ts`)

           new application.default(context, next, this.router)  
   })
</code></pre></div>
<p dir="auto">Here is my script to set permissions on each request per script:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="async setPermissions(context: Record&lt;string, any&gt;, next: Function):Promise&lt;void&gt; {
        const desc = { name: &quot;read&quot;, path: &quot;./Applications/Preferences/Preferences.ts&quot; } as const
        await Deno.permissions.request(desc)
        await next()
}"><pre class="notranslate"><code class="notranslate">async setPermissions(context: Record&lt;string, any&gt;, next: Function):Promise&lt;void&gt; {
        const desc = { name: "read", path: "./Applications/Preferences/Preferences.ts" } as const
        await Deno.permissions.request(desc)
        await next()
}
</code></pre></div>
<p dir="auto">A way to grant the above permission without having to go to the terminal for every request after its reset would be welcome.</p>
<p dir="auto">Note:  I have to revoke the permissions after each script is done just to  enforce a type of module level permission</p>
<p dir="auto">Sorry if this has been asked or discussed before. Can't seem to find it.</p>
<p dir="auto">Can I make sure imported scripts are in Sandbox mode even if my own script isn't.</p>
<p dir="auto"><code class="notranslate">// I'd like to make sure this imported script doesn't have access to disk or network even though my code is networking</code><br>
<code class="notranslate">import { SomeFeature} from "https://url.com/some-small-library.ts";</code></p>