Files
FastGPT/document/content/docs/introduction/guide/dashboard/workflow/sandbox.en.mdx
T
Archer aaa7d17ef1 V4.14.9 dev (#6555)
* feat: encapsulate logger (#6535)

* feat: encapsulate logger

* update engines

---------

Co-authored-by: archer <545436317@qq.com>

* next config

* dev shell

* Agent sandbox (#6532)

* docs: switch to docs layout and apply black theme (#6533)

* feat: add Gemini 3.1 models

- Add gemini-3.1-pro-preview (released February 19, 2026)
- Add gemini-3.1-flash-lite-preview (released March 3, 2026)

Both models support:
- 1M context window
- 64k max response
- Vision
- Tool choice

* docs: switch to docs layout and apply black theme

- Change layout from notebook to docs
- Update logo to icon + text format
- Apply fumadocs black theme
- Simplify global.css (keep only navbar and TOC styles)
- Fix icon components to properly accept className props
- Add mobile text overflow handling
- Update Node engine requirement to >=20.x

* doc

* doc

* lock

* fix: ts

* doc

* doc

---------

Co-authored-by: archer <archer@archerdeMac-mini.local>
Co-authored-by: archer <545436317@qq.com>

* Doc (#6493)

* cloud doc

* doc refactor

* doc move

* seo

* remove doc

* yml

* doc

* fix: tsconfig

* fix: tsconfig

* sandbox version (#6497)

* sandbox version

* add sandbox log

* update lock

* fix

* fix: sandbox

* doc

* add console

* i18n

* sandbxo in agent

* feat: agent sandbox

* lock

* feat: sandbox ui

* sandbox check exists

* env tempalte

* doc

* lock

* sandbox in chat window

* sandbox entry

* fix: test

* rename var

* sandbox config tip

* update sandbox lifecircle

* update prompt

* rename provider test

* sandbox logger

* yml

---------

Co-authored-by: Archer <archer@fastgpt.io>
Co-authored-by: archer <archer@archerdeMac-mini.local>

* perf: sandbox error tip

* Add sandbox limit and fix some issue (#6550)

* sandbox in plan

* fix: some issue

* fix: test

* editor default path

* fix: comment

* perf: sandbox worksapce

* doc

* perf: del sandbox

* sandbox build

* fix: test

* fix: pr comment

---------

Co-authored-by: Ryo <whoeverimf5@gmail.com>
Co-authored-by: Archer <archer@fastgpt.io>
Co-authored-by: archer <archer@archerdeMac-mini.local>
2026-03-16 17:09:25 +08:00

97 lines
2.0 KiB
Plaintext

---
title: Code Execution
description: FastGPT Code Execution node overview
---
![alt text](/imgs/image.png)
## Function
Runs simple JavaScript code for complex data processing. Code executes in a sandbox with no access to network requests, DOM, or async operations. For advanced use cases, use an HTTP node instead.
**Important Notes**
- Self-hosted users must deploy the `fastgpt-sandbox` image and set the `CODE_SANDBOX_URL` environment variable.
- The sandbox enforces a 10-second max runtime and 32 MB memory limit.
## Variable Input
Add the variables your code needs via custom inputs. In the code's `main` function, destructure them by matching name.
As shown above, the custom inputs include `data1` and `data2`, which can be destructured with the same names in the `main` function.
## Result Output
You must return an object.
In custom outputs, add variable names to retrieve values from the corresponding object keys. For example, the image above returns:
```json
{
result: data1,
data2
}
```
This object has 2 keys: `result` and `data2` (JS shorthand where key = data2, value = data2). You can then add 2 custom output variables to access the values under each key.
## Built-in JS Global Variables
### delay
Returns after a 1-second delay:
```js
async function main({data1, data2}){
await delay(1000)
return {
result: "111"
}
}
```
### countToken
```js
function main({input}){
return {
result: countToken(input)
}
}
```
![alt text](/imgs/image-1.png)
### strToBase64 (added in v4.8.11)
Useful for converting SVG images to base64 format for display.
```js
function main({input}){
return {
/*
param1: input - the string to convert
param2: base64 prefix
*/
result: strToBase64(input,'data:image/svg+xml;base64,')
}
}
```
![alt text](/imgs/image-2.png)
### createHmac
Works the same as Node.js crypto's `createHmac` method.
```js
function main({secret}){
const {sign,timestamp} = createHmac('sha256',secret)
return {
sign,timestamp
}
}
```