Agent Sandbox Registry

模板

node-web

Node.js web service runtime for Express, Fastify and other frameworks

能力 shell files code ports · 状态 official

abx template install alibaba-agent-sandbox/awesome-templates//node-web

在每个 provider 上

alicloud-express可安装构建 · 怎么做
alicloud-container已有模板 id 才能创建 · 怎么做
cubesandbox已有模板 id 才能创建 · 怎么做
e2b已有模板 id 才能创建 · 怎么做
opensandbox需要先推送镜像 · 怎么做

说明

node-web

中文版 | English


English

Node.js 20 web service sandbox environment, suited for rapid development and deployment with Express, Fastify, Koa, and similar frameworks.

Environment

Category Details
Base image python:3.12-slim (Node.js installed for the web runtime)
Node.js Node.js 20.x + npm
Global tools yarn, nodemon, pm2
System tools curl, wget, git, jq
Resources 1 CPU / 2048 MB memory
Exposed port 3000

Installation

Install from a local path:

abx template install ./node-web --registry-type local

Install from GitHub:

abx template install alibaba-agent-sandbox/awesome-templates//node-web

Usage

Create a sandbox instance:

abx create --template node-web

Initialize an Express project inside the sandbox and start it:

abx exec <sandbox-id> -- bash -c "
cd /workspace && \
npm init -y && \
npm install express && \
cat > index.js << 'EOF'
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;

app.get('/', (req, res) => {
  res.json({ message: 'Hello from Agent Sandbox!' });
});

app.listen(port, () => {
  console.log('Server running on port ' + port);
});
EOF
node index.js
"

Using the Python SDK:

from agent_sandbox import Sandbox

sandbox = Sandbox.create_sync(template="node-web")

# Write the server code
sandbox.files.write("/workspace/index.js", """
const http = require('http');
const server = http.createServer((req, res) => {
    res.writeHead(200, {'Content-Type': 'application/json'});
    res.end(JSON.stringify({status: 'ok'}));
});
server.listen(3000);
""")

# Start the service
sandbox.commands.run("node /workspace/index.js &")

# Test access
result = sandbox.commands.run("curl -s http://localhost:3000")
print(result.stdout)

Configuration

Environment Variables

Variable Description Default
NODE_ENV Node.js runtime environment production
PORT Web service listen port 3000

Managing Processes with pm2

pm2 is preinstalled and available for process management:

# Start the service
pm2 start index.js --name my-app

# Check status
pm2 status

# View logs
pm2 logs my-app

Development Mode with nodemon

During development, use nodemon for hot reload:

NODE_ENV=development nodemon index.js

Notes


中文

Node.js 20 Web 服务沙箱环境,适用于 Express、Fastify、Koa 等框架的快速开发与部署。

环境说明

类别 内容
基础镜像 python:3.12-slim(镜像内安装 Node.js,作为 Web 运行时)
Node.js Node.js 20.x + npm
全局工具 yarn、nodemon、pm2
系统工具 curl、wget、git、jq
资源配置 1 CPU / 2048 MB 内存
暴露端口 3000

安装方式

从本地安装:

abx template install ./node-web --registry-type local

从 GitHub 安装:

abx template install alibaba-agent-sandbox/awesome-templates//node-web

使用示例

创建沙箱实例:

abx create --template node-web

在沙箱中初始化 Express 项目并启动:

abx exec <sandbox-id> -- bash -c "
cd /workspace && \
npm init -y && \
npm install express && \
cat > index.js << 'EOF'
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;

app.get('/', (req, res) => {
  res.json({ message: 'Hello from Agent Sandbox!' });
});

app.listen(port, () => {
  console.log('Server running on port ' + port);
});
EOF
node index.js
"

使用 Python SDK:

from agent_sandbox import Sandbox

sandbox = Sandbox.create_sync(template="node-web")

# 写入服务器代码
sandbox.files.write("/workspace/index.js", """
const http = require('http');
const server = http.createServer((req, res) => {
    res.writeHead(200, {'Content-Type': 'application/json'});
    res.end(JSON.stringify({status: 'ok'}));
});
server.listen(3000);
""")

# 启动服务
sandbox.commands.run("node /workspace/index.js &")

# 测试访问
result = sandbox.commands.run("curl -s http://localhost:3000")
print(result.stdout)

配置说明

环境变量

变量名 说明 默认值
NODE_ENV Node.js 运行环境 production
PORT Web 服务监听端口 3000

使用 pm2 管理进程

pm2 已预装,可用于进程管理:

# 启动服务
pm2 start index.js --name my-app

# 查看状态
pm2 status

# 查看日志
pm2 logs my-app

使用 nodemon 开发模式

开发阶段可使用 nodemon 实现热重载:

NODE_ENV=development nodemon index.js

注意事项

Deploy and local e2e

Install and register this template:

abx template install alibaba-agent-sandbox/awesome-templates//node-web

From this directory (build, push, and register):

abx deploy

From the repository root, with agent-sandbox-server and httpx installed:

python3 scripts/run_local_e2e.py

That starts python3 commands.py in this directory and runs e2e_test.py.

文件