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

Method Create

pkg/sandbox/factory.go:22–84  ·  view source on GitHub ↗

Create 根据配置创建沙箱

(config *types.SandboxConfig)

Source from the content-addressed store, hash-verified

20
21// Create 根据配置创建沙箱
22func (f *Factory) Create(config *types.SandboxConfig) (Sandbox, error) {
23 if config == nil {
24 // 默认使用本地沙箱
25 config = &types.SandboxConfig{
26 Kind: types.SandboxKindLocal,
27 WorkDir: ".",
28 }
29 }
30
31 switch config.Kind {
32 case types.SandboxKindLocal:
33 return NewLocalSandbox(&LocalSandboxConfig{
34 WorkDir: config.WorkDir,
35 EnforceBoundary: config.EnforceBoundary,
36 AllowPaths: config.AllowPaths,
37 WatchFiles: config.WatchFiles,
38 Settings: config.Settings,
39 })
40
41 case types.SandboxKindDocker:
42 return nil, errors.New("docker sandbox not implemented yet")
43
44 case types.SandboxKindK8s:
45 return nil, errors.New("k8s sandbox not implemented yet")
46
47 case types.SandboxKindAliyun:
48 // 阿里云沙箱需要使用 cloud.NewAliyunSandbox() 直接创建
49 return nil, errors.New("aliyun sandbox: use cloud.NewAliyunSandbox() directly")
50
51 case types.SandboxKindVolcengine:
52 // 火山引擎沙箱需要使用 cloud.NewVolcengineSandbox() 直接创建
53 return nil, errors.New("volcengine sandbox: use cloud.NewVolcengineSandbox() directly")
54
55 case types.SandboxKindRemote:
56 // 通用远程沙箱
57 if config.Extra == nil {
58 return nil, errors.New("remote sandbox requires extra configuration")
59 }
60
61 baseURL, _ := config.Extra["base_url"].(string)
62 apiKey, _ := config.Extra["api_key"].(string)
63 apiSecret, _ := config.Extra["api_secret"].(string)
64
65 timeout := 30 * time.Second
66 if t, ok := config.Extra["timeout"].(time.Duration); ok {
67 timeout = t
68 }
69
70 return NewRemoteSandbox(&RemoteSandboxConfig{
71 BaseURL: baseURL,
72 APIKey: apiKey,
73 APISecret: apiSecret,
74 WorkDir: config.WorkDir,
75 Timeout: timeout,
76 })
77
78 case types.SandboxKindMock:
79 return NewMockSandbox(), nil

Callers 1

mainFunction · 0.95

Calls 3

NewLocalSandboxFunction · 0.85
NewRemoteSandboxFunction · 0.85
NewMockSandboxFunction · 0.70

Tested by

no test coverage detected