Workflow nodesOfficial documentation9 min readWorkflow nodes

List of Permitted Python Modules for FastGPT Sandbox V2

Overview of FastGPT Sandbox V2 Python Restrictions FastGPT Sandbox V2 enforces a secure Python execution environment by restricting all imported code to a…

Overview of FastGPT Sandbox V2 Python Restrictions

FastGPT Sandbox V2 enforces a secure Python execution environment by restricting all imported code to a pre-approved whitelist of modules. This mitigation prevents unauthorized system calls, network communications, and direct file system modifications within the workflow node. Only the modules listed below may be imported and used in sandbox code.

Complete Whitelisted Python Modules

All permitted modules are grouped by functional category below:

Math and Numerical Computing

ModuleDescription
mathMathematical functions
cmathComplex number math
decimalDecimal floating-point arithmetic
fractionsFraction arithmetic
randomRandom number generation
statisticsStatistical functions

Data Structures and Algorithms

ModuleDescription
collectionsContainer data types
arrayArrays
heapqHeap queue
bisectArray bisection
queueQueues
copyShallow and deep copy

Functional Programming

ModuleDescription
itertoolsIterator tools
functoolsHigher-order functions
operatorStandard operators

String and Text Processing

ModuleDescription
stringString constants
reRegular expressions
difflibDiff calculation
textwrapText wrapping
unicodedataUnicode database
codecsCodec registry

Date and Time

ModuleDescription
datetimeDate and time
timeTime access
calendarCalendar

Data Serialization

ModuleDescription
jsonJSON encoding/decoding
csvCSV file handling
base64Base64 encoding/decoding
binasciiBinary-to-ASCII conversion
structByte string parsing

Encryption and Hashing

ModuleDescription
hashlibHash algorithms
hmacHMAC message authentication
secretsSecure random numbers
uuidUUID generation

Types and Abstractions

ModuleDescription
typingType hints
abcAbstract base classes
enumEnumeration types
dataclassesData classes
contextlibContext managers

Other Utilities

ModuleDescription
pprintPretty printing
weakrefWeak references

Third-Party Libraries

ModuleDescription
numpyNumerical computing
pandasData analysis
matplotlibData visualization

Prohibited Python Modules

The sandbox blocks all modules not included in the whitelist. Explicitly prohibited modules include os, sys, subprocess, socket, urllib, http, and requests. Additionally, any module that enables system calls, network access, or direct file system operations is restricted from execution.

Step-by-Step Valid Usage

  1. Add a Sandbox V2 node to your FastGPT workflow.
  2. In the integrated code editor, import only whitelisted modules. For example, to compute a weighted average using statistics and math:
import math
import statistics

values = [10, 20, 30]
weights = [1, 2, 3]
weighted_mean = statistics.mean(v * w for v, w in zip(values, weights))
print(f\"Weighted mean: {weighted_mean:.2f}\")
  1. Execute the node. The sandbox will run the code successfully, as all imported modules are permitted.
  2. Attempting to import a prohibited module such as os will result in a security-restricted import failure.

Source: FastGPT official source

Applicability and version scope

Use this page for the documented Workflow nodes scenario. Confirm the FastGPT, dependency, API, and deployment versions in the official source before applying a change.

Safety guardrails

Use [REDACTED_CREDENTIAL] for credentials and private data. Confirm the documented environment and version before review.

Rollback guidance

Restore the prior technical-content authority snapshot. Restore saved configuration and data snapshots, then repeat the smallest verification scenario.