@@ -83,7 +83,14 @@ func NewWorker(app app.App) *Worker {
8383
8484var upgrader = websocket.Upgrader {} // use default options
8585
86- func (me * Worker ) DenoArgs (deno string ) []string {
86+ type SandboxMethod string
87+
88+ var (
89+ SandboxMethodFetch SandboxMethod = "fetch"
90+ SandboxMethodRun SandboxMethod = "run"
91+ )
92+
93+ func (me * Worker ) DenoArgs (deno string , method SandboxMethod ) []string {
8794 args := []string {
8895 "--allow-net" ,
8996 "--allow-import" ,
@@ -115,9 +122,14 @@ func (me *Worker) DenoArgs(deno string) []string {
115122 args = append (
116123 args ,
117124 fmt .Sprintf ("--allow-read=%s,%s,%s" , appDir , deno , npmCache ),
118- fmt .Sprintf ("--allow-write=%s" , me .App .DataDir ()),
119125 )
120126
127+ if method == SandboxMethodRun {
128+ args = append (args , fmt .Sprintf ("--allow-write=%s" , me .App .Dir ()))
129+ } else {
130+ args = append (args , fmt .Sprintf ("--allow-write=%s" , me .App .DataDir ()))
131+ }
132+
121133 return args
122134 }
123135
@@ -133,8 +145,14 @@ func (me *Worker) DenoArgs(deno string) []string {
133145 args = append (
134146 args ,
135147 fmt .Sprintf ("--allow-read=%s,%s,%s,%s" , appDir , target , deno , npmCache ),
136- fmt .Sprintf ("--allow-write=%s,%s" , me .App .DataDir (), filepath .Join (target , "data" )),
137148 )
149+
150+ if method == SandboxMethodRun {
151+ args = append (args , fmt .Sprintf ("--allow-write=%s,%s" , me .App .Dir (), target ))
152+ } else {
153+ args = append (args , fmt .Sprintf ("--allow-write=%s,%s" , me .App .DataDir (), filepath .Join (target , "data" )))
154+ }
155+
138156 return args
139157}
140158
@@ -151,7 +169,7 @@ func (me *Worker) Start() error {
151169 }
152170
153171 args := []string {"run" }
154- args = append (args , me .DenoArgs (deno )... )
172+ args = append (args , me .DenoArgs (deno , SandboxMethodFetch )... )
155173 input := strings.Builder {}
156174 encoder := json .NewEncoder (& input )
157175 encoder .SetEscapeHTML (false )
@@ -462,7 +480,7 @@ func (me *Worker) Command(ctx context.Context, args ...string) (*exec.Cmd, error
462480 }
463481
464482 denoArgs := []string {"run" }
465- denoArgs = append (denoArgs , me .DenoArgs (deno )... )
483+ denoArgs = append (denoArgs , me .DenoArgs (deno , SandboxMethodRun )... )
466484
467485 payload := strings.Builder {}
468486 encoder := json .NewEncoder (& payload )
0 commit comments