This document describes how to generate Java and Go client code from E2B prototype specifications, covering both the Sandbox API (OpenAPI) and envd gRPC services (Protobuf).
- Install
openapi-generator - Install
buf - Install Git CLI to clone the E2B specification repository locally; all generation operations are executed in the corresponding local directories
💡 Tip: All code generation steps below are executed locally. You need to enter the corresponding directory before running generation commands.
| Type | Specification Address | Description |
|---|---|---|
| Sandbox API | e2b-dev/E2B/spec/openapi.yml |
OpenAPI 3.0 specification |
| envd gRPC | e2b-dev/E2B/spec/envd |
Protobuf specification directory |
git clone https://github.com/e2b-dev/E2B.git
cd E2Bopenapi-generator generate \
-i ./spec/openapi.yml \
-g java \
--library okhttp-gson \
-o ./api-client \
--additional-properties=\
artifactId=e2b-api-client,\
groupId=io.openkruise.agents.client.e2b,\
apiPackage=io.openkruise.agents.client.e2b.api,\
modelPackage=io.openkruise.agents.client.e2b.api.models,\
invokerPackage=io.openkruise.agents.client.e2b.api.invoker,\
dateLibrary=java8,\
disallowAdditionalPropertiesIfNotPresent=falseCopy the generated code to the corresponding directory in the agents-api repository:
# Source path: ./api-client/src/main/java/io/openkruise/agents/client/e2b/api
# Target path: agents-api/e2b/java/src/main/java/io/openkruise/agents/client/e2b/api📦 Target repository path: e2b/java/src/main/java/io/openkruise/agents/client/e2b/api
# If not already cloned
git clone https://github.com/e2b-dev/E2B.git
cd spec/envdCreate a buf.gen.java.yaml file in the spec/envd directory:
version: v1
plugins:
- plugin: java
out: ./java/src/main/java
- plugin: grpc-java
out: ./java/src/main/java
managed:
enabled: true
optimize_for: SPEED
java_package_prefix:
default: io.openkruise.agents.client.runtime.envdbuf generate --template buf.gen.java.yamlCopy the generated code to the corresponding directory in the agents-api repository:
# Source path: ./java/src/main/java/io/openkruise/agents/client/runtime/envd
# Target path: agents-api/runtime/java/src/main/java/io/openkruise/agents/client/runtime/envd📦 Target repository path: runtime/java/src/main/java/io/openkruise/agents/client/runtime/envd
⚠️ Important: Since the Java SDK has not yet been published to Maven Central, thee2b/javamodule directly depends on the envd code inruntime/java.
Synchronization Rules:
When runtime/java/.../runtime related code is modified, it must be synchronized to the corresponding directory in
e2b/java/.../runtime:
runtime/java/src/main/java/io/openkruise/agents/client/runtime
↓ Sync to
e2b/java/src/main/java/io/openkruise/agents/client/e2b/runtime
Reasons:
- The
e2b/javamodule depends on the runtime code inruntime/java - Before Maven publication, both modules need to maintain code consistency to avoid compilation errors or runtime exceptions
💡 Future Optimization: Once the runtime package is published to Maven Central, you only need to add the runtime dependency in
e2b/java'spom.xml, and manual code synchronization will no longer be required.
# If not already cloned
git clone https://github.com/e2b-dev/E2B.git
cd E2B
⚠️ Note: The Go code generated from the original OpenAPI specification has naming conflicts. The following field names inspec/openapi.ymlneed to be modified first:
NewSandbox→CreateSandboxRequestNewTeamAPIKey→CreateTeamAPIKeyRequestNewVolume→CreateVolumeRequest
Execute in the E2B directory:
openapi-generator generate \
-i ./spec/openapi.yml \
-g go \
-o ./api \
--additional-properties=\
packageName=client,\
withGoMod=false,\
generateInterfaces=true,\
contextApi=true,\
returnError=true,\
enumClassPrefix=trueCopy the generated code to the corresponding directory in the agents-api repository:
# Source path: ./api
# Target path: agents-api/e2b/api📦 Target repository path: e2b/api
# If not already cloned
git clone https://github.com/e2b-dev/E2B.git
cd E2B/spec/envdCreate a buf.gen.go.yaml file in the spec/envd directory:
version: v1
plugins:
- plugin: go
out: ./go
opt: paths=source_relative
- plugin: connect-go
out: ./go
opt: paths=source_relative
managed:
enabled: true
optimize_for: SPEED
go_package_prefix:
default: github.com/openkruise/agents-api/runtime/envdExecute in the E2B/spec/envd directory:
buf generate --template buf.gen.go.yamlCopy the generated code to the corresponding directory in the agents-api repository:
# Source path: ./go/envd
# Target path: agents-api/runtime/envd📦 Target repository path: runtime/envd