Skip to content
Merged
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
2 changes: 1 addition & 1 deletion docker/templates/base.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ RUN echo "deb ${DEBIAN_MIRROR}" > /etc/apt/sources.list \
&& rm -rf /var/lib/apt/lists/*

# Install Python dependencies
ARG PYTHON_PACKAGES="httpx==0.27.2 requests==2.32.3 jinja2==3.1.6 PySocks httpx[socks]"
ARG PYTHON_PACKAGES="httpx==0.27.2 requests==2.33.0 jinja2==3.1.6 PySocks httpx[socks]"

RUN pip3 install --no-cache-dir ${PYTHON_PACKAGES}
2 changes: 1 addition & 1 deletion docker/templates/production.dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Production environment Dockerfile template
ARG PYTHON_VERSION=dhi.io/python:3-debian13-sfw-ent-dev
ARG DEBIAN_MIRROR="http://deb.debian.org/debian testing main"
ARG PYTHON_PACKAGES="httpx==0.27.2 requests==2.32.3 jinja2==3.1.6 PySocks httpx[socks]"
ARG PYTHON_PACKAGES="httpx==0.27.2 requests==2.33.0 jinja2==3.1.6 PySocks httpx[socks]"
ARG NODEJS_VERSION=v20.11.1
ARG NODEJS_MIRROR="https://npmmirror.com/mirrors/node"
ARG TARGETARCH
Expand Down
4 changes: 2 additions & 2 deletions docker/templates/test.dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Test environment Dockerfile template
ARG GOLANG_VERSION=1.23.9
ARG GOLANG_VERSION=1.25.0
ARG PYTHON_VERSION=docker.io/langgenius/python:3-debian13-sfw-ent-dev
ARG DEBIAN_MIRROR="http://deb.debian.org/debian testing main"
ARG PYTHON_PACKAGES="httpx==0.27.2 requests==2.32.3 jinja2==3.1.6 PySocks httpx[socks]"
ARG PYTHON_PACKAGES="httpx==0.27.2 requests==2.33.0 jinja2==3.1.6 PySocks httpx[socks]"
ARG NODEJS_VERSION=v20.11.1
ARG NODEJS_MIRROR="https://npmmirror.com/mirrors/node"
ARG GOLANG_MIRROR="https://golang.org/dl"
Expand Down
4 changes: 2 additions & 2 deletions docker/versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
versions:
# Base images
python: "dhi.io/python:3-debian13-sfw-ent-dev"
golang: "1.24.13"
golang: "1.25.0"
nodejs: "v20.20.0"

# Python packages (unified configuration)
python_packages: "httpx==0.27.2 requests==2.32.3 jinja2==3.1.6 PySocks httpx[socks]"
python_packages: "httpx==0.27.2 requests==2.33.0 jinja2==3.1.6 PySocks httpx[socks]"

# System packages
system_packages:
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module github.com/langgenius/dify-sandbox

go 1.24.11
go 1.25.0

require (
github.com/gin-gonic/gin v1.10.0
github.com/google/uuid v1.6.0
github.com/seccomp/libseccomp-golang v0.11.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -29,10 +30,9 @@ require (
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.17.0 // indirect
golang.org/x/crypto v0.45.0 // indirect
golang.org/x/net v0.47.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.31.0 // indirect
golang.org/x/crypto v0.50.0 // indirect
golang.org/x/net v0.53.0 // indirect
golang.org/x/sys v0.43.0 // indirect
golang.org/x/text v0.36.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
)
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65E
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
golang.org/x/arch v0.17.0 h1:4O3dfLzd+lQewptAHqjewQZQDyEdejz3VwgeYwkZneU=
golang.org/x/arch v0.17.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
golang.org/x/crypto v0.50.0 h1:zO47/JPrL6vsNkINmLoo/PH1gcxpls50DNogFvB5ZGI=
golang.org/x/crypto v0.50.0/go.mod h1:3muZ7vA7PBCE6xgPX7nkzzjiUq87kRItoJQM1Yo8S+Q=
golang.org/x/net v0.53.0 h1:d+qAbo5L0orcWAr0a9JweQpjXF19LMXJE8Ey7hwOdUA=
golang.org/x/net v0.53.0/go.mod h1:JvMuJH7rrdiCfbeHoo3fCQU24Lf5JJwT9W3sJFulfgs=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI=
golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg=
golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
Expand Down
8 changes: 7 additions & 1 deletion internal/core/runner/nodejs/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ func (p *NodeJsRunner) Run(

// create a new process
cmd := exec.Command(configuration.NodejsPath, buildCommandArgs(script_path, uid, options)...)
cmd.Env = []string{}
cmd.Env = []string{
// The sandbox child loads a Go c-shared library to install seccomp.
// Disable Go runtime features that may issue housekeeping syscalls after
// the seccomp filter is active; the prescript removes this before running
// user code.
"GODEBUG=decoratemappings=0,containermaxprocs=0,updatemaxprocs=0",
}
cmd.ExtraFiles = []*os.File{codeReader}

if len(configuration.AllowedSyscalls) > 0 {
Expand Down
1 change: 1 addition & 0 deletions internal/core/runner/nodejs/prescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const gid = parseInt(argv[3])
const options = JSON.parse(argv[4])

difySeccomp(uid, gid, options['enable_network'])
delete process.env.GODEBUG

const code = fs.readFileSync(3, 'utf8')
eval(code)
1 change: 1 addition & 0 deletions internal/core/runner/python/prescript.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def excepthook(type, value, tb):
{{preload}}

lib.DifySeccomp({{uid}}, {{gid}}, {{enable_network}})
os.environ.pop("GODEBUG", None)

with os.fdopen(3, "rb") as code_fd:
code = code_fd.read().decode("utf-8")
Expand Down
8 changes: 7 additions & 1 deletion internal/core/runner/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ func (p *PythonRunner) Run(
bootstrapPath,
LIB_PATH,
)
cmd.Env = []string{}
cmd.Env = []string{
// The sandbox child loads a Go c-shared library to install seccomp.
// Disable Go runtime features that may issue housekeeping syscalls after
// the seccomp filter is active; the prescript removes this before running
// user code.
"GODEBUG=decoratemappings=0,containermaxprocs=0,updatemaxprocs=0",
}
cmd.Dir = LIB_PATH
cmd.ExtraFiles = []*os.File{codeReader}

Expand Down
1 change: 1 addition & 0 deletions internal/static/nodejs_syscall/syscalls_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var ALLOW_SYSCALLS = []int{

syscall.SYS_READLINK,
syscall.SYS_DUP3,
syscall.SYS_EVENTFD2,
}

var ALLOW_ERROR_SYSCALLS = []int{
Expand Down
1 change: 1 addition & 0 deletions internal/static/nodejs_syscall/syscalls_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var ALLOW_SYSCALLS = []int{

// epoll
syscall.SYS_EPOLL_CTL, syscall.SYS_EPOLL_PWAIT,
syscall.SYS_EVENTFD2,
}

var ALLOW_ERROR_SYSCALLS = []int{
Expand Down
5 changes: 3 additions & 2 deletions internal/static/python_syscall/syscalls_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ var ALLOW_SYSCALLS = []int{
syscall.SYS_NEWFSTATAT, syscall.SYS_FSTAT, syscall.SYS_FCNTL, syscall.SYS_IOCTL, syscall.SYS_LSEEK, syscall.SYS_GETDENTS64,
syscall.SYS_WRITE, syscall.SYS_CLOSE, syscall.SYS_OPENAT, syscall.SYS_READ,
// thread
syscall.SYS_FUTEX,
syscall.SYS_FUTEX, syscall.SYS_SCHED_GETAFFINITY,
// memory
syscall.SYS_MMAP, syscall.SYS_BRK, syscall.SYS_MPROTECT, syscall.SYS_MUNMAP, syscall.SYS_RT_SIGRETURN,
syscall.SYS_MREMAP,
syscall.SYS_MREMAP, syscall.SYS_MADVISE,

// user/group
syscall.SYS_SETGROUPS, syscall.SYS_SETGID, syscall.SYS_SETUID, syscall.SYS_GETUID,
Expand All @@ -36,6 +36,7 @@ var ALLOW_SYSCALLS = []int{
syscall.SYS_TIME,

syscall.SYS_RT_SIGPROCMASK, syscall.SYS_SIGALTSTACK, SYS_GETRANDOM,
syscall.SYS_EVENTFD2,
}

var ALLOW_ERROR_SYSCALLS = []int{
Expand Down
5 changes: 3 additions & 2 deletions internal/static/python_syscall/syscalls_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ var ALLOW_SYSCALLS = []int{
syscall.SYS_FSTAT, syscall.SYS_FCNTL,

// thread
syscall.SYS_FUTEX,
syscall.SYS_FUTEX, syscall.SYS_SCHED_GETAFFINITY,

// memory
syscall.SYS_MMAP, syscall.SYS_BRK, syscall.SYS_MPROTECT, syscall.SYS_MUNMAP, syscall.SYS_RT_SIGRETURN, syscall.SYS_RT_SIGPROCMASK,
syscall.SYS_SIGALTSTACK, syscall.SYS_MREMAP,
syscall.SYS_SIGALTSTACK, syscall.SYS_MREMAP, syscall.SYS_MADVISE,

// user/group
syscall.SYS_SETGROUPS, syscall.SYS_SETGID, syscall.SYS_SETUID, syscall.SYS_GETUID,
Expand All @@ -41,6 +41,7 @@ var ALLOW_SYSCALLS = []int{

// get random
syscall.SYS_GETRANDOM,
syscall.SYS_EVENTFD2,
}

var ALLOW_ERROR_SYSCALLS = []int{
Expand Down
Loading