Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions internal/core/runner/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
_ "embed"
"fmt"
"io"
"log/slog"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -85,6 +86,28 @@ func (p *PythonRunner) Run(
}
}

if configuration.AllowedSyscallFilePath != "" {
if _, err := os.Stat(configuration.AllowedSyscallFilePath); err == nil {
content, _ := os.ReadFile(configuration.AllowedSyscallFilePath)

parts := strings.Split(strings.TrimSpace(string(content)), ",")
var numbers []int
for _, part := range parts {
if part == "" {
continue
}
num, _ := strconv.Atoi(strings.TrimSpace(part))
numbers = append(numbers, num)
}
if len(numbers) > 0 {
configuration.AllowedSyscalls = append(configuration.AllowedSyscalls, numbers...)
slog.Info("config syscall length", "info", len(configuration.AllowedSyscalls))
}
} else {
slog.Error("file not exists", "err", err, "file path", configuration.AllowedSyscallFilePath)
}
}

if len(configuration.AllowedSyscalls) > 0 {
cmd.Env = append(cmd.Env,
fmt.Sprintf("ALLOWED_SYSCALLS=%s",
Expand Down
3 changes: 2 additions & 1 deletion internal/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ type DifySandboxGlobalConfigurations struct {
EnableNetwork bool `yaml:"enable_network"`
EnablePreload bool `yaml:"enable_preload"`
AllowedSyscalls []int `yaml:"allowed_syscalls"`
AllowedSyscallFilePath string `yaml:"allowed_syscall_filepath"`
LogPath string `yaml:"log_path"`
Proxy struct {
Socks5 string `yaml:"socks5"`
Https string `yaml:"https"`
Http string `yaml:"http"`
} `yaml:"proxy"`
}
}
Loading