e2b-dev / E2B

Secure open source cloud runtime for AI apps & AI agents
https://e2b.dev/docs
Apache License 2.0
7.02k stars 458 forks source link

How can i use swagger API's from E2b sandbox ? #455

Open om-tericsoft1 opened 1 month ago

om-tericsoft1 commented 1 month ago

I have integrated Swagger APIs into my project running in the e2b sandbox environment, but they are not functioning as expected. The Swagger UI loads correctly, but the API endpoints are either unresponsive or return unexpected errors. I have tested the same APIs outside of the e2b environment, and they work without any issues.

linear[bot] commented 1 month ago

E2B-1003 How can i use swagger API's from E2b sandbox ?

ValentaTomas commented 4 weeks ago

@om-tericsoft1 Can you share the E2B SDK code you are using for running your project and how you are accessing the API endpoints?

om-tericsoft1 commented 2 weeks ago

@ValentaTomas here is a sample code.

async def py_hosting_app(code,prisma):

sandbox = Sandbox(template="base", timeout=300,api_key=E2B_API_KEY)

# Run these I/O-bound operations asynchronously
await asyncio.to_thread(sandbox.filesystem.write, "/home/user/main.py", code)
await asyncio.to_thread(sandbox.filesystem.write, "/home/user/prisma.schema", prisma)

result = sandbox.process.start("pip install fastapi uvicorn prisma fastapi-cors")
result.wait()
print(result.stdout)

result = sandbox.process.start("prisma migrate --schema=/home/user/prisma.schema")
result.wait()
print(result.stdout)

result = sandbox.process.start("prisma generate --schema=/home/user/prisma.schema")
result.wait()
print(result.stdout)
print(result.stderr)

await asyncio.to_thread(sandbox.process.start, "uvicorn main:app --reload")

# Get the URL
url = sandbox.get_hostname(8000)
print(f"node app is running at: https://{url}")

return url