MCPcopy Create free account
hub / github.com/astercloud/aster / NewVolcengineSandbox

Function NewVolcengineSandbox

pkg/sandbox/cloud/volcengine.go:44–108  ·  view source on GitHub ↗

NewVolcengineSandbox 创建火山引擎沙箱

(config *VolcengineConfig)

Source from the content-addressed store, hash-verified

42
43// NewVolcengineSandbox 创建火山引擎沙箱
44func NewVolcengineSandbox(config *VolcengineConfig) (*VolcengineSandbox, error) {
45 if config.Endpoint == "" {
46 return nil, errors.New("endpoint is required")
47 }
48 if config.AccessKey == "" || config.SecretKey == "" {
49 return nil, errors.New("access credentials are required")
50 }
51
52 // 设置默认值
53 if config.Region == "" {
54 config.Region = "cn-beijing"
55 }
56 if config.WorkDir == "" {
57 config.WorkDir = "/workspace"
58 }
59 if config.Timeout == 0 {
60 config.Timeout = 60 * time.Second
61 }
62 if config.CPU == 0 {
63 config.CPU = 2
64 }
65 if config.Memory == 0 {
66 config.Memory = 4096
67 }
68
69 // 创建远程沙箱基础
70 remoteConfig := &sandbox.RemoteSandboxConfig{
71 BaseURL: config.Endpoint,
72 APIKey: config.AccessKey,
73 APISecret: config.SecretKey,
74 WorkDir: config.WorkDir,
75 Timeout: config.Timeout,
76 Properties: map[string]any{
77 "region": config.Region,
78 "cpu": config.CPU,
79 "memory": config.Memory,
80 },
81 }
82
83 remoteSandbox, err := sandbox.NewRemoteSandbox(remoteConfig)
84 if err != nil {
85 return nil, fmt.Errorf("create remote sandbox: %w", err)
86 }
87
88 // 创建 MCP 客户端
89 mcpClient := NewMCPClient(&MCPClientConfig{
90 Endpoint: config.Endpoint,
91 AccessKeyID: config.AccessKey,
92 AccessKeySecret: config.SecretKey,
93 Timeout: config.Timeout,
94 })
95
96 vs := &VolcengineSandbox{
97 RemoteSandbox: remoteSandbox,
98 config: config,
99 mcpClient: mcpClient,
100 }
101

Callers 1

testVolcengineFunction · 0.92

Calls 3

initSessionMethod · 0.95
NewRemoteSandboxFunction · 0.92
NewMCPClientFunction · 0.85

Tested by

no test coverage detected